Example #1
0
    void drawImage(const colorspaces::Image& image, Gtk::DrawingArea* drawingArea){
      /*convert to RGB*/
      colorspaces::ImageRGB8 img_rgb8(image);
      Glib::RefPtr<Gdk::Pixbuf> imgBuff = 
	Gdk::Pixbuf::create_from_data((const guint8*)img_rgb8.data,
				      Gdk::COLORSPACE_RGB,
				      false,
				      8,
				      img_rgb8.width,
				      img_rgb8.height,
				      img_rgb8.step);
      
      Glib::RefPtr<Gdk::Window> window = drawingArea->get_window();
      const Glib::RefPtr< const Gdk::GC > gc;/*empty*/
      window->draw_pixbuf(gc,
			  imgBuff,
			  0,0,/*starting point from imgBuff*/
			  0,0,/*starting point into drawable*/
			  imgBuff->get_width(),
			  imgBuff->get_height(),
			  Gdk::RGB_DITHER_NONE, 0, 0);
      drawingArea->set_size_request(img_rgb8.width,
				    img_rgb8.height);
    }
Example #2
0
	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;
	}
void ValidationPanel::refresh()
{
	// update the label
	crn::StringUTF8 lab = "<span font_desc=\"" + Config::GetFont() + "\">" + title + "</span>";
	lab += " (";
	lab += nelem;
	lab += ")";
	auto *labw = get_label_widget();
	auto *llab = dynamic_cast<Gtk::Label*>(labw);
	if (llab)
		llab->set_markup(lab.CStr());
	else
		set_label(lab.CStr());
	

	if (/*(positions.size() != elements.size()) ||*/ (dispw <= 0) || (disph <= 0) || locked)
		return;

	Glib::RefPtr<Gdk::Window> win = da.get_window();
	if (win)
	{
		// if the drawing area is fully created
		// create a buffer
		Glib::RefPtr<Gdk::Pixmap> pm = Gdk::Pixmap::create(win, dispw, disph);
		// clear the buffer
		pm->draw_rectangle(da_gc, true, 0, 0, dispw, disph);
		int offset = -int(scroll.get_value());

		Cairo::RefPtr<Cairo::Context> cc = pm->create_cairo_context();


		// draw the words
		for (const ValidationPanel::ElementList::value_type &el : elements)
		{
			if (!el.second.empty())
			{
				int by = positions[el.second.begin()->first].Y;
				int ey = by;
				for (const ValidationPanel::ElementCluster::value_type &w : el.second)
				{
					int y = positions[w.first].Y + w.second.img->get_height();
					if (y > ey) ey = y;
				}
				if ((el.first == elements.rbegin()->first) && (ey < disph))
				{
					// fill till the end of the display
					ey = disph;
				}
				ValidationPanel::set_color(cc, el.first);
				cc->rectangle(0, by + offset, dispw, ey - by);
				cc->fill();
			}
			for (const ValidationPanel::ElementCluster::value_type &w : el.second)
			{
				Glib::RefPtr<Gdk::Pixbuf> wpb = w.second.img;

				pm->draw_pixbuf(da_gc, wpb, 0, 0, positions[w.first].X, positions[w.first].Y + offset, w.second.img->get_width(), w.second.img->get_height(), Gdk::RGB_DITHER_NONE, 0, 0);
			}
		}

		// draw the mark
		if (mark.size() > 1)
		{
			cc->set_source_rgb(1.0, 0, 0);
			cc->move_to(mark.front().X, mark.front().Y + offset);
			for (size_t tmp = 1; tmp < mark.size(); ++tmp)
			{
				cc->line_to(mark[tmp].X, mark[tmp].Y + offset);
			}
			cc->stroke();
		}

		// copy pixmap to drawing area
		win->draw_drawable(da_gc, pm, 0, 0, 0, 0);
	}

}
Example #4
0
	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;
	}