コード例 #1
0
	void
	inputCallback(const sensor_msgs::Image::ConstPtr& color_image_msg, const sensor_msgs::PointCloud2::ConstPtr& pointcloud_msg)
	{
		//ROS_INFO("Input Callback");

		//Elements needed for recognition




		// convert color image to cv::Mat
		cv_bridge::CvImageConstPtr color_image_ptr;
		cv::Mat color_image;
		convertColorImageMessageToMat(color_image_msg, color_image_ptr, color_image);

		// get color image from point cloud
		pcl::PointCloud<pcl::PointXYZRGB> point_cloud_src;
		pcl::fromROSMsg(*pointcloud_msg, point_cloud_src);

// cv::Mat color_image = cv::Mat::zeros(point_cloud_src.height, point_cloud_src.width, CV_8UC3);
// for (unsigned int v=0; v<point_cloud_src.height; v++)
// {
// for (unsigned int u=0; u<point_cloud_src.width; u++)
// {
// pcl::PointXYZRGB point = point_cloud_src(u,v);
// if (isnan_(point.z) == false)
// color_image.at<cv::Point3_<unsigned char> >(v,u) = cv::Point3_<unsigned char>(point.b, point.g, point.r);
// }
// }
		cv::Mat color_image_copy = color_image.clone();
		int half_side_length = 50;
		cv::rectangle(color_image_copy, cv::Point(color_image.cols/2-half_side_length, color_image.rows/2-half_side_length),
				cv::Point(color_image.cols/2+half_side_length, color_image.rows/2+half_side_length), CV_RGB(0, 255, 0), 3);
		cv::imshow("color image", color_image_copy);

		char key= cv::waitKey(20);
		//std::cout<<key;
		//char key = 'c';
		//std::cout<<"gut"<<std::endl;

		//std::cout<< "How do you want to name the image? (The name of the data cloud is the same as the one of the image"<<std::endl;


		if (key=='c')
		{
			//The image captured is in 'color_image_copy' and then classified
			Classifier C;
			C.imageExtractROI(color_image_copy);
			C.classify();

		}
		else if (key=='q')
			ros::shutdown();


	}
コード例 #2
0
int main () {


	DataBase db("Database.txt", FALSE);
	std::string name;
	int cl;
	float error=0;

	for(int i=0; i<db.getSize(); i++){
		Classifier c;

		name = db.getElement(i);
		std::cout<<"Analizying image "<<name<<" ..."<<std::endl;
		cv::Mat image= cv::imread(name+".jpg");


		std::cout<<"Image read..."<<std::endl;

		if(name[0]=='O' || name[0]=='P'){

			std::cout <<"ROI Extraction..."<<std::endl;
			std::cout<<"Image size: "<<image.size()<<std::endl;
			c.imageExtractROI(image);

		}
		else
			c.setImage(image);

		std::cout<<"Image set..."<<std::endl;
		c.classify();
		cl = c.getClass();

		if(name[0]=='P' && cl!=PEN) error++;
		else if(name[0]=='S' && cl!=SCISSORS) error++;
		else if (name[0]=='O' && cl!=NO_IDENTIFIED) error++;


	}

	std::cout<<"Error= "<<error/db.getSize()<<std::endl;




	return 0;
}