/*
* blobdetection.cpp
- Created on: 23/03/2017
- Author: zubair khan
*/
#include <ros ros.h="">
#include <stdlib.h>
#include <iostream>
#include <opencv2 highgui="" highgui.hpp="">
#include <opencv2 opencv.hpp="">
#include <opencv2 imgproc="" imgproc.hpp="">
#include <opencv2 core="" core.hpp="">
#include <librealsense rs.hpp="">
#include <librealsense rscore.hpp="">
#include <cv_bridge cv_bridge.h="">
#include <image_transport image_transport.h="">
#include <sensor_msgs image_encodings.h="">
#include <geometry_msgs twist.h="">
#include <geometry_msgs vector3.h="">
#include <pcl point_types.h="">
#include <pcl_ros transforms.h="">
#include <pcl conversions.h="">
#include <pcl pclpointcloud2.h="">
#include <pcl_conversions pcl_conversions.h="">
#include <boost foreach.hpp="">
#include <geometry_msgs point.h="">
#include <sensor_msgs pointcloud2.h="">
namespace enc = sensor_msgs::image_encodings;
using namespace std;
static const char WINDOW[] = "Image Processed";
static const char RESULT[] = "Tracking";
sensor_msgs::PointCloud2 my_pcl;
//Use method of ImageTransport to create image publisher
image_transport::Publisher pub;
bool hasNewPcl = false;
int LowerH = 170;
int LowerS = 150;
int LowerV = 60;
int UpperH = 179;
int UpperS = 255;
int UpperV = 255;
int posX;
int posY;
ros::NodeHandle *n;
sensor_msgs::PointCloud2 depth;
pcl::PointCloud < pcl::PointXYZ > pcl_cloud;
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
void depthcallback (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
my_pcl = *cloud_msg;
hasNewPcl = true;
cout<<"here"<<endl;< p="">
}
void getXYZ(int x, int y)
{
int arrayPosition = ymy_pcl.row_step + xmy_pcl.point_step;
int arrayPosX = arrayPosition + my_pcl.fields[0].offset;
int arrayPosY = arrayPosition + my_pcl.fields[1].offset;
int arrayPosZ = arrayPosition + my_pcl.fields[2].offset;
float X ;
float Y ;
float Z ;
memcpy(&X, &my_pcl.data[arrayPosX], sizeof(float));
memcpy(&Y, &my_pcl.data[arrayPosY], sizeof(float));
memcpy(&Z, &my_pcl.data[arrayPosZ], sizeof(float));
geometry_msgs::Point p;
// put data into the point p
p.x = X;
p.y = Y;
p.z = Z;
std::cout<<"z:"<<p.z<<std::endl; }<="" p="">
void blobDetectionCallback(const sensor_msgs::ImageConstPtr& original_image)
{
//Convert from the ROS image message to a CvImage suitable for working with OpenCV for processing
cv_bridge::CvImagePtr cv_ptr;
try
{
cv_ptr = cv_bridge::toCvCopy(original_image, enc::BGR8);
}
catch (cv_bridge::Exception& e)
{
//if there is an error during conversion, display it
ROS_ERROR("tutorialROSOpenCV::main.cpp::cv_bridge exception: %s", e.what());
return;
}
cv::Mat img_mask,img_hsv;
cv::cvtColor(cv_ptr->image,img_hsv,CV_BGR2HSV);
cv::inRange(img_hsv,cv::Scalar(LowerH,LowerS,LowerV),cv::Scalar(UpperH,UpperS,UpperV),img_mask);
cv::erode(img_mask, img_mask, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)) );
cv::dilate(img_mask, img_mask, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)) );
cv::erode(img_mask, img_mask, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)) );
cv::dilate(img_mask, img_mask, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)) );
//Calculate the moments of the thresholded image
cv:: Moments oMoments = moments(img_mask);
double dM01 = oMoments.m01;
double dM10 = oMoments.m10;
double dArea = oMoments.m00;
posX = dM10 / dArea;
posY = dM01 / dArea;
std::cout<<"posx:"<<posX<<"posy:"<<posY<<std::endl;
cv::circle(img_mask, cv::Point(posX, posY), 10, cv::Scalar(0,255,255), 2);
cv::Mat Points;
cv::findNonZero(img_mask,Points);
cv::Rect Min_Rect=boundingRect(Points);
cv::rectangle(img_mask,Min_Rect.tl(),Min_Rect.br(),cv::Scalar(255,0,0),1);
cv::imshow(RESULT, img_mask);
//Convert the CvImage to a ROS image message and publish it on the "camera/image_processed" topic.
pub ...
(more)
ros::NodeHandle *n;
sensor_msgs::PointCloud2 depth; pcl::PointCloud < pcl::PointXYZ > pcl_cloud;
void depthcallback (const sensor_msgs::PointCloud2ConstPtr& cloud_msg) { my_pcl = *cloud_msg; hasNewPcl = true; }
and this is how i am subscribing to image call back
Looks like there's a bug in your code. I can't tell what's going on in the screenshot; please edit your question to replace the screenshot with the full command you're running, the full error message from your node, and the full source code for your node (or a link to source code).
It's best to not use screen shots of text - it's hard to read and isn't searchable.
https://pastebin.com/i71RQcU2 this is my full code,,
please have a look
I can't access that link from my network. Why not just paste it here on this page?
its a very big code.. its out of comment reach
i pasted in pastebin ,, are you not able to see my code ??