// [ref] ${VXL_HOME}/contrib/mul/fhs/tools/find_matches.cxx
int fhs_find_matches_example(int argc, char *argv[])
{
	vul_arg<vcl_string> image1_path("-i1", "Input image 1");
	vul_arg<vcl_string> image2_path("-i2", "Input image 2");
	vul_arg<vcl_string> output_image1_path("-o1", "Output image 1", "output1.png");
	vul_arg<vcl_string> output_image2_path("-o2", "Output image 1", "output2.png");
	vul_arg<unsigned> level("-L", "Image pyramid level to work on", 2);
	vul_arg<unsigned> nc("-n", "Number of points to select", 10);
	vul_arg<unsigned> w("-w", "Half width of filters", 7);
	vul_arg<double> f("-f", "Relative strength of intensity vs shape", 0.1);

	vul_arg_parse(argc, argv);

	if (image1_path() == "" || image2_path() == "")
	{
		local::print_usage();
		return 0;
	}

	// ============================================
	// Attempt to load in images
	// ============================================

	vimt_image_2d_of<vxl_byte> image1, image2;
	image1.image() = vil_load(image1_path().c_str());
	if (image1.image().size() == 0)
	{
		vcl_cerr << "Unable to read in image from " << image1_path() << vcl_endl;
		return 1;
	}
	image2.image() = vil_load(image2_path().c_str());
	if (image2.image().size() == 0)
	{
		vcl_cerr <<" Unable to read in image from " << image2_path() << vcl_endl;
		return 1;
	}

	// ============================================
	// Build image pyramids and select chosen level
	// ============================================
	vimt_gaussian_pyramid_builder_2d<vxl_byte> pyr_builder;
	vimt_image_pyramid image_pyr1, image_pyr2;
	pyr_builder.build(image_pyr1, image1);
	pyr_builder.build(image_pyr2, image2);

	const vimt_image_2d_of<vxl_byte> &image1_L = static_cast<const vimt_image_2d_of<vxl_byte> &>(image_pyr1(level()));
	const vimt_image_2d_of<vxl_byte> &image2_L = static_cast<const vimt_image_2d_of<vxl_byte> &>(image_pyr2(level()));

	// ====================================================
	// Apply corner operator to image1_L and select corners
	// ====================================================

	vimt_image_2d_of<float> corner_im;
	corner_im.set_world2im(image1_L.world2im());
	vil_corners(image1_L.image(), corner_im.image());

	vcl_vector<unsigned> pi, pj;
	float threshold = 4.0f;
	vil_find_peaks_3x3(pi, pj, corner_im.image(), threshold);

	// Evaluate corner strength at each point (pi[i], pj[i])
	unsigned n = pi.size();
	vcl_vector<float> corner_str(n);
	for (unsigned i = 0 ; i < n; ++i)
		corner_str[i] = corner_im.image()(pi[i], pj[i]);

	// Sort and generate a list of image points and equivalent world points
	vcl_vector<unsigned> index;
	mbl_index_sort(corner_str, index);

	unsigned n_c = vcl_min(nc(),n);
	vcl_vector<vgl_point_2d<int> > im_pts(n_c);
	vcl_vector<vgl_point_2d<double> > w_pts(n_c);
	vimt_transform_2d im2w = image1_L.world2im().inverse();
	for (unsigned i = 0; i < n_c; ++i)
	{
		im_pts[i] = vgl_point_2d<int>(pi[index[n - 1 - i]], pj[index[n - 1 - i]]);
		w_pts[i] = im2w(pi[index[n - 1 - i]], pj[index[n - 1 - i]]);
	}


	// ========================================================
	// Extract patches around each selected point and normalise
	// ========================================================
	vcl_vector<vil_image_view<float> > patch(n_c);
	vcl_vector<vgl_point_2d<double> > patch_ref(n_c);  // Reference point
	int ni = image1.image().ni();
	int nj = image1.image().nj();
	for (unsigned i = 0; i < n_c; ++i)
	{
		// Select region around point, allowing for image edges.
		int ilo = vcl_max(0, int(im_pts[i].x() - w()));
		int ihi = vcl_min(ni - 1, int(im_pts[i].x() + w()));
		int jlo = vcl_max(0, int(im_pts[i].y() - w()));
		int jhi = vcl_min(nj - 1, int(im_pts[i].y() + w()));

		// Compute position of reference point relative to corner
		int kx = im_pts[i].x() - ilo;
		int ky = im_pts[i].y() - jlo;
		patch_ref[i] = vgl_point_2d<double>(kx, ky);
		vil_convert_cast(vil_crop(image1_L.image(), ilo, 1 + ihi - ilo, jlo, 1 + jhi - jlo), patch[i]);
		vil_math_normalise(patch[i]);
	}

	// Construct tree structure for points
	vcl_vector<vcl_pair<int, int> > pairs;
	mbl_minimum_spanning_tree(w_pts, pairs);

	assert(pairs.size() == n_c - 1);

	// Draw tree into image for display purposes
	local::draw_tree(image1.image(), w_pts, pairs);

	if (vil_save(image1.image(), output_image1_path().c_str()))
	{
		vcl_cout << "Saved output image 1 to " << output_image1_path() << vcl_endl;
	}

	// =================================================
	// Construct the arc model from the points and pairs
	// =================================================

	vcl_vector<fhs_arc> arcs(n_c - 1);
	int root_node = pairs[0].first;
	for (unsigned i = 0; i < pairs.size(); ++i)
	{
		int i1 = pairs[i].first;
		int i2 = pairs[i].second;
		vgl_vector_2d<double> dp = w_pts[i2] - w_pts[i1];
		double sd_x = vcl_max(0.1 * ni, 0.2 * dp.length());
		double sd_y = vcl_max(0.1 * nj, 0.2 * dp.length());
		arcs[i] = fhs_arc(i1, i2, dp.x(), dp.y(), sd_x * sd_x, sd_y * sd_y);
	}

	// =================================================
	// Apply filters to image2 (initially to whole image)
	// =================================================
	vcl_vector<vimt_image_2d_of<float> > feature_response(n_c);
	for (unsigned i = 0; i < n_c; ++i)
	{
		// Apply to whole image in first instance
		// Ideally would crop a region around expected position
		vimt_normalised_correlation_2d(image2_L, feature_response[i], patch[i], patch_ref[i], float());

		// Need good values to be small, not large, so apply -ve factor
		vil_math_scale_values(feature_response[i].image(), -f());
	}

	// ======================================================
	// Use fhs_searcher to locate equivalent points on image2
	// ======================================================

	fhs_searcher searcher;
	searcher.set_tree(arcs, root_node);
	searcher.search(feature_response);
	vcl_vector<vgl_point_2d<double> > pts2;
	searcher.best_points(pts2);

	// Draw tree into image for display purposes
	local::draw_tree(image2.image(), pts2, pairs);

	if (vil_save(image2.image(), output_image2_path().c_str()))
	{
		vcl_cout << "Saved output image 2 to " << output_image2_path() << vcl_endl;
	}

	return 0;
}
Пример #2
0
void MainWindow::createActions()
{
  // file
  updateAction = new QAction(trUtf8("Обновить"), this);
  updateAction->setShortcut(tr("F5"));
  connect(updateAction, SIGNAL(triggered()), this, SLOT(update()));
  
  loadServicesAction = new QAction(trUtf8("Загрузка услуг"), this);
  connect(loadServicesAction, SIGNAL(triggered()), this, SLOT(loadServices()));

  loadServicesMtsAction = new QAction(trUtf8("Загрузка услуг MTC"), this);
  connect(loadServicesMtsAction, SIGNAL(triggered()), this, SLOT(loadServicesMts()));

  loadPaysAction = new QAction(trUtf8("Загрузка платежей"), this);
  connect(loadPaysAction, SIGNAL(triggered()), this, SLOT(loadPays()));

  exitAction = new QAction(trUtf8("Выход"), this);
  exitAction->setShortcut(tr("Ctrl+Q"));
  exitAction->setStatusTip(trUtf8("Выйти из программы"));
  connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));

  // refs
  clientsAction = new QAction(trUtf8("Клиенты"), this);
  // clientsAction->setStatusTip(trUtf8("Информация по клиентам"));
  connect(clientsAction, SIGNAL(triggered()), this, SLOT(clients()));

  abonentTypesAction = new QAction(trUtf8("Типы абонентов"), this);
  // abonentTypesAction->setStatusTip(trUtf8("Информация по клиентам"));
  connect(abonentTypesAction, SIGNAL(triggered()), this, SLOT(abonentTypes()));

  tplansAction = new QAction(trUtf8("Тарифные планы"), this);
  // tplansAction->setStatusTip(trUtf8("Информация по клиентам"));
  connect(tplansAction, SIGNAL(triggered()), this, SLOT(tplans()));

  operatorsAction = new QAction(trUtf8("Операторы"), this);
  operatorsAction->setStatusTip(trUtf8("Операторы"));
  connect(operatorsAction, SIGNAL(triggered()), this, SLOT(operators()));

  servicesAction = new QAction(trUtf8("Услуги"), this);
  // tplansAction->setStatusTip(trUtf8("Информация по клиентам"));
  connect(servicesAction, SIGNAL(triggered()), this, SLOT(services()));

  paysAction = new QAction(trUtf8("Платежи"), this);
  paysAction->setStatusTip(trUtf8("Информация по платежам"));
  connect(paysAction, SIGNAL(triggered()), this, SLOT(pays()));

  correctionsAction = new QAction(trUtf8("Корректировки"), this);
  connect(correctionsAction, SIGNAL(triggered()), this, SLOT(corrections()));

  arcsAction = new QAction(trUtf8("Архив"), this);
  arcsAction->setStatusTip(trUtf8("Архив"));
  arcsAction->setEnabled(userGr_ == 0);
  connect(arcsAction, SIGNAL(triggered()), this, SLOT(arcs()));
    
  // operations
  calc4abonentsAction = new QAction(trUtf8("1 Рассчет по абонентам"), this);
  connect(calc4abonentsAction, SIGNAL(triggered()), this, SLOT(calc4abonents()));

  calc4clientsAction = new QAction(trUtf8("2 Рассчет по клиентам (+счета)"), this);
  connect(calc4clientsAction, SIGNAL(triggered()), this, SLOT(calc4clients()));

  files4clientsAction = new QAction(trUtf8("Счета по по клиентам"), this);
  connect(files4clientsAction, SIGNAL(triggered()), this, SLOT(files4clients()));

  // reports
  noAbonentsAction = new QAction(trUtf8("Начисления без абонентов"), this);
  connect(noAbonentsAction, SIGNAL(triggered()), this, SLOT(noAbonents()));

  noAccrualsAction = new QAction(trUtf8("Абоненты без начислений"), this);
  connect(noAccrualsAction, SIGNAL(triggered()), this, SLOT(noAccruals()));


  aboutAction = new QAction(tr("&About"), this);
  aboutAction->setStatusTip(tr("Show the application's About box"));
  connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
}