コード例 #1
0
ファイル: main.cpp プロジェクト: TheAquaMan/Navoh
	VideoWidget()
	{
		vc.Init();
		vc.Play();
		vc.get_frame(pixbuf);
		set_size_request(pixbuf->get_width(), pixbuf->get_height());
	}
コード例 #2
0
ファイル: main.cpp プロジェクト: TheAquaMan/Navoh
	virtual bool on_expose_event(GdkEventExpose* )
	{
		Glib::RefPtr<Gdk::Drawable> drawable = get_window();

		vc.get_frame(pixbuf);

		drawable->draw_pixbuf(get_style()->get_bg_gc(Gtk::STATE_NORMAL),
				pixbuf->scale_simple(get_width(), get_height(), Gdk::INTERP_BILINEAR),
				0, 0, 0, 0, -1 , -1, Gdk::RGB_DITHER_NONE, 0, 0);

		Gdk::Point rect[4], barcode_center;
		string str;

		bool res = decode_barcode(pixbuf, rect, str, 100);

		if (res)
		{
			Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context();

			cr->set_line_width(3);
			cr->set_source_rgb(1, 0.0, 0.0);

			cr->move_to(rect[0].get_x(), rect[0].get_y() );
			cr->line_to(rect[1].get_x(), rect[1].get_y() );
			cr->line_to(rect[2].get_x(), rect[2].get_y() );
			cr->line_to(rect[3].get_x(), rect[3].get_y() );
			cr->line_to(rect[0].get_x(), rect[0].get_y() );

			cr->stroke();

			BarcodePropertyEstimation distance(get_width(), get_height(),
					rect[0].get_x(), rect[0].get_y(),
					rect[1].get_x(), rect[1].get_y(),
					rect[2].get_x(), rect[2].get_y(),
					rect[3].get_x(), rect[3].get_y());


			Glib::RefPtr<Pango::Layout> pango_layout = Pango::Layout::create(cr);

			Pango::FontDescription desc("Arial Rounded MT Bold");
			desc.set_size(14 * PANGO_SCALE);
			pango_layout->set_font_description(desc);
			pango_layout->set_alignment(Pango::ALIGN_CENTER);

			double dir = distance.calcDirection();
			string dir_str;

			if (dir > 2.3)
				dir_str = "right";
			else if (dir < -2.3)
				dir_str = "left";
			else
				dir_str = "front";

			double dist = distance.calcDistance();
			string text = "Object ID: " + str +
					"\nDistance: " + lexical_cast<string>(int(dist * 100) / 100) + "." +
					lexical_cast<string>(int(dist * 100) % 100) +
					"\nDirection: " + dir_str;

			pango_layout->set_text(text);

			Gdk::Point* max_x, *min_x, *max_y, *min_y;
			boost::function<bool (Gdk::Point, Gdk::Point)> compare;

			compare = bind(less<int>(), bind(&Gdk::Point::get_x, _1), bind(&Gdk::Point::get_x, _2));
			max_x = max_element(rect, rect + 4, compare);
			min_x =	min_element(rect, rect + 4, compare);

			compare = bind(less<int>(), bind(&Gdk::Point::get_y, _1), bind(&Gdk::Point::get_y, _2));
			max_y = max_element(rect, rect + 4, compare);
			min_y =	min_element(rect, rect + 4, compare);

			barcode_center = Gdk::Point(
					(max_x->get_x() + min_x->get_x()) / 2,
					(max_y->get_y() + min_y->get_y()) / 2);

			const Pango::Rectangle extent = pango_layout->get_pixel_logical_extents();

			cr->move_to(get_width() - extent.get_width() - 10,
					get_height() - extent.get_height() - 10);

			pango_layout->show_in_cairo_context(cr);

			DetectedBarcode barcode(str, dir_str, distance.calcDistance());
			vector<DetectedBarcode> vec;
			vec.push_back(barcode);

			ostringstream ostr;
			xmlpp::Document document1;

			listDetectedBarcodesToXML(document1.create_root_node("ObjectList"), vec);

			document1.write_to_stream(ostr, "UTF-8");

			mut.lock();
			strXML = ostr.str();
			mut.unlock();

		}

		return true;
	}
コード例 #3
0
ファイル: main.cpp プロジェクト: fulcrum7/Navoh
	virtual bool on_expose_event(GdkEventExpose* )
	{
		Glib::RefPtr<Gdk::Drawable> drawable = get_window();

		vc.get_frame(pixbuf);

		drawable->draw_pixbuf(get_style()->get_bg_gc(Gtk::STATE_NORMAL), pixbuf,
				0, 0, 0, 0, -1 , -1, Gdk::RGB_DITHER_NONE, 0, 0);

		Gdk::Point rect[4], barcode_center;
		string str;

		bool res = decode_barcode(pixbuf, rect, str, 500);

		if (res)
		{
			Cairo::RefPtr<Cairo::Context> cr = drawable->create_cairo_context();

			cr->set_line_width(3);
			cr->set_source_rgb(1, 0.0, 0.0);

			cr->move_to(rect[0].get_x(), rect[0].get_y());
			cr->line_to(rect[1].get_x(), rect[1].get_y());
			cr->line_to(rect[2].get_x(), rect[2].get_y());
			cr->line_to(rect[3].get_x(), rect[3].get_y());
			cr->line_to(rect[0].get_x(), rect[0].get_y());
			cr->stroke();

			DataMtxPlace distance(get_width(), get_height(),
					rect[0].get_x(), rect[0].get_y(),
					rect[1].get_x(), rect[1].get_y(),
					rect[2].get_x(), rect[2].get_y(),
					rect[3].get_x(), rect[3].get_y());

			cout << "Distance: " << distance.calcDistance() <<
					"\tSquare: " <<  distance.calcSquare() <<
					"\tDirection: " << distance.calcDirection() << endl;

			Glib::RefPtr<Pango::Layout> pango_layout = Pango::Layout::create(cr);

			Pango::FontDescription desc("Arial Rounded MT Bold");
			desc.set_size(14 * PANGO_SCALE);
			pango_layout->set_font_description(desc);
			pango_layout->set_alignment(Pango::ALIGN_CENTER);

			string text = "Msg: " + str + "\nDist: " +
					lexical_cast<string>(distance.calcDistance()) + "\nDir: " +
					lexical_cast<string>(distance.calcDirection());

			pango_layout->set_text(text);

			Gdk::Point* max_x, *min_x, *max_y, *min_y;
			boost::function<bool (Gdk::Point, Gdk::Point)> compare;

			compare = bind(less<int>(), bind(&Gdk::Point::get_x, _1), bind(&Gdk::Point::get_x, _2));
			max_x = max_element(rect, rect + 4, compare);
			min_x =	min_element(rect, rect + 4, compare);

			compare = bind(less<int>(), bind(&Gdk::Point::get_y, _1), bind(&Gdk::Point::get_y, _2));
			max_y = max_element(rect, rect + 4, compare);
			min_y =	min_element(rect, rect + 4, compare);

			barcode_center = Gdk::Point(
					(max_x->get_x() + min_x->get_x()) / 2,
					(max_y->get_y() + min_y->get_y()) / 2);

			const Pango::Rectangle extent = pango_layout->get_pixel_logical_extents();

			cr->move_to(barcode_center.get_x() - extent.get_width() / 2,
					barcode_center.get_y() - extent.get_height() / 2);

			pango_layout->show_in_cairo_context(cr);

//			cr->set_source_rgba(0, 0, 0, 0.6);
//
//			int i = 0;
//			if (center_barcode.get_x() < get_width() / 3)
//				i = 0;
//			else if (center_barcode.get_x() > (2 * get_width() / 3))
//				i = 2;
//			else
//				i = 1;
//
//			cr->rectangle(i * get_width() / 3,  0, i * get_width() / 3 + get_width() / 3, get_height());
//			cr->fill_preserve();
		}

//		cr->set_source_rgba(0, 0, 0, 0.6);
//		cr->move_to(get_width() / 3, 0);
//		cr->line_to(get_width() / 3, get_height());
//		cr->move_to(2 * get_width() / 3, 0);
//		cr->line_to(2 * get_width() / 3, get_height());
//		cr->stroke();

		return true;
	}