bool MS_Blueball_Decide::onStep()
{
	LOG(LTRACE) << "MS_Blueball_Decide::step\n";

	blobs_ready = hue_ready = false;

	try {
		int id = 0;
		int i;
		Types::Blobs::Blob *currentBlob;
		Types::DrawableContainer Blueballs;

		// iterate through all found blobs
		for (i = 0; i < blobs.GetNumBlobs(); i++ )
		{
			currentBlob = blobs.GetBlob(i);

//			// get mean color from area coverd by blob (from hue component)
//			double me = currentBlob->Mean(&h);
//			double st = currentBlob->StdDev(&h);

			// get blob bounding rectangle and ellipse
			CvBox2D r2 = currentBlob->GetEllipse();

//			// blob moments
//			double m00, m10, m01, m11, m02, m20;
//			double M11, M02, M20, M7;
//
//			// calculate moments
//			m00 = currentBlob->Moment(0,0);
//			m01 = currentBlob->Moment(0,1);
//			m10 = currentBlob->Moment(1,0);
//			m11 = currentBlob->Moment(1,1);
//			m02 = currentBlob->Moment(0,2);
//			m20 = currentBlob->Moment(2,0);
//
//			M11 = m11 - (m10*m01)/m00;
//			M02 = m02 - (m01*m01)/m00;
//			M20 = m20 - (m10*m10)/m00;
//
//			// for circle it should be ~0.0063
//			M7 = (M20*M02-M11*M11) / (m00*m00*m00*m00);

			std::cout << "Center: " << r2.center.x << "," << r2.center.y << "\n";
			++id;

			Blueballs.add(new Types::Ellipse(Point(r2.center.x, r2.center.y), Size(r2.size.width, r2.size.height), r2.angle));
		}

		out_balls.write(Blueballs);

		newImage->raise();

		return true;
	} catch (...) {
		LOG(LERROR) << "MS_Blueball_Decide::onNewImage failed\n";
		return false;
	}
}
bool MS_Barcode_Decide::onStep()
{
	blobs_ready = hue_ready = false;

	try {
		int i;
		IplImage h = IplImage(hue_img);
		Types::Blobs::Blob *currentBlob;
		Types::DrawableContainer signs;

		// iterate through all found blobs
		for (i = 0; i < blobs.GetNumBlobs(); i++ )
		{
			currentBlob = blobs.GetBlob(i);

			// get mean color from area coverd by blob (from hue component)
			double me = currentBlob->Mean(&h);
			double st = currentBlob->StdDev(&h);

			// get blob bounding rectangle and ellipse
			//CvBox2D be = currentBlob->GetEllipse();
			cv::Rect bb = currentBlob->GetBoundingBox();

			signs.add(new Types::Rectangle(bb.x, bb.y, bb.width, bb.height));

		}

		out_signs.write(signs);

		newImage->raise();

		return true;
	} catch (...) {
		LOG(LERROR) << "MS_Sign_Decide::onNewImage failed\n";
		return false;
	}
}
Esempio n. 3
0
bool ExtractBlocks_Processor::onStep()
{
	LOG(LTRACE) << "ExtractBlocks_Processor::step\n";
  
	blobs_ready = hue_ready = false;

	try {
		int id = 0;
		int i;
		IplImage h = IplImage(hue_img);
		Types::Blobs::Blob *currentBlob;
		Types::DrawableContainer blocks;

		// iterate through all found blobs
		for (i = 0; i < blobs.GetNumBlobs(); i++ )
		{
			currentBlob = blobs.GetBlob(i);

			// get blob bounding rectangle
			CvRect r2 = currentBlob->GetBoundingBox();

			++id;

			blocks.add(new Types::Rectangle(r2.x, r2.y, r2.width, r2.height));

			out_blocks.write(blocks);

			newImage->raise();
		}

		return true;
	}   catch (...) {
		LOG(LERROR) << "ExtractBlocks_Processor::onNewImage failed\n";
		return false;
  }
}