ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

instead, create ur own package with the source code below

include <ros ros.h="">

include <opencv cv.h="">

include <opencv highgui.h="">

include <opencv cvaux.h="">

include <image_transport image_transport.h="">

include <cv_bridge cvbridge.h="">

include <cassert>

CvHaarClassifierCascade *cascade; CvMemStorage *storage;

int detectFaces( IplImage *img );

void imageCallback(const sensor_msgs::ImageConstPtr& msg) { sensor_msgs::CvBridge bridge;

IplImage *src ;

try { src = bridge.imgMsgToCv(msg, "bgr8"); } catch (sensor_msgs::CvBridgeException& e) { ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str()); }

if(src) {

    CvCapture *capture;
char      *filename = "/home/haarcascade_frontalface_alt.xml";
cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );
storage = cvCreateMemStorage( 0 );
//assert( cascade );

cvNamedWindow( "video", 1 );
 src->origin = 0;

    detectFaces( src );

    cvWaitKey(1);

} } int detectFaces( IplImage* img )
{

int i;

CvSeq *faces = cvHaarDetectObjects(img,cascade,storage,1.1,3,0 /*CV_HAAR_DO_CANNY_PRUNNING*/,
cvSize( 40, 40 ) );

for( i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ ) 
{
    CvRect *r = ( CvRect* )cvGetSeqElem( faces, i );
    cvRectangle( img,cvPoint( r->x, r->y ),cvPoint( r->x + r->width, r->y + r->height ),                                                                                   CV_RGB( 255, 0, 0 ), 1, 8, 0 );
}

cvShowImage( "video", img );
    return 1;

}

int main(int argc, char **argv) { ros::init(argc, argv, "video"); ros::NodeHandle nh; cvStartWindowThread(); image_transport::ImageTransport it(nh); image_transport::Subscriber sub = it.subscribe("camera/image_raw", 1, imageCallback); ros::spin(); }