Ask Your Question

sam3891's profile - activity

2015-03-16 06:26:48 -0600 received badge  Enthusiast
2015-03-15 16:21:16 -0600 commented answer How to detect a fallen person with opencv using a webcam?

Hi,

I need to detect only a person who has already fallen.

2015-03-13 07:06:07 -0600 asked a question How to detect a fallen person with opencv using a webcam?

Hello,

In my project, I should be able to detect a person on the floor in an image. I am using a Festo Robotino 2010 model, which has Logitech C250, laser scanner and IR detectors. What is the best way to go about it in OpenCV?

2015-03-04 05:06:56 -0600 asked a question Error: dims > 0 && hist.data in function calcBackProject

Hello,

I am getting the error: (-215) dims > 0 && hist.data in function calcBackProject, when compiling my code. What could be some possible causes for this? I am using the camshiftdemo.cpp example in my code and I get the error.

void imageCallback(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
{
    //Always copy, returning a mutable CvImage
    //OpenCV expects color images to use BGR channel order.
    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;
}

Rect trackWindow;
int hsize = 16;
float hranges[] = {0,180};
const float* phranges = hranges;


namedWindow( "Histogram", 0 );
namedWindow( "CamShift Demo", 0 );
setMouseCallback( "CamShift Demo", onMouse, 0 );
createTrackbar( "Vmin", "CamShift Demo", &vmin, 256, 0 );
createTrackbar( "Vmax", "CamShift Demo", &vmax, 256, 0 );
createTrackbar( "Smin", "CamShift Demo", &smin, 256, 0 );


Mat frame, hsv, hue, mask, hist, histimg = Mat::zeros(200, 320, CV_8UC3), backproj;
//    bool paused = false;


(cv_ptr->image).copyTo(image);

//if( !paused )
    //{
        cvtColor(image, hsv, COLOR_BGR2HSV);

        if( trackObject )
        {
            int _vmin = vmin, _vmax = vmax;

            inRange(hsv, Scalar(0, smin, MIN(_vmin,_vmax)),
                    Scalar(180, 256, MAX(_vmin, _vmax)), mask);
            int ch[] = {0, 0};
            hue.create(hsv.size(), hsv.depth());
            mixChannels(&hsv, 1, &hue, 1, ch, 1);

            if( trackObject < 0 )
            {
                Mat roi(hue, selection), maskroi(mask, selection);
                calcHist(&roi, 1, 0, maskroi, hist, 1, &hsize, &phranges);
                normalize(hist, hist, 0, 255, CV_MINMAX);

                trackWindow = selection;
                trackObject = 1;

                histimg = Scalar::all(0);
                int binW = histimg.cols / hsize;
                Mat buf(1, hsize, CV_8UC3);
                for( int i = 0; i < hsize; i++ )
                    buf.at<Vec3b>(i) = Vec3b(saturate_cast<uchar>(i*180./hsize), 255, 255);
                cvtColor(buf, buf, CV_HSV2BGR);

                for( int i = 0; i < hsize; i++ )
                {
                    int val = saturate_cast<int>(hist.at<float>(i)*histimg.rows/255);
                    rectangle( histimg, Point(i*binW,histimg.rows),
                               Point((i+1)*binW,histimg.rows - val),
                               Scalar(buf.at<Vec3b>(i)), -1, 8 );
                }
            }

            calcBackProject(&hue, 1, 0, hist, backproj, &phranges);
            backproj &= mask;
            RotatedRect trackBox = CamShift(backproj, trackWindow,
                                TermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ));
            if( trackWindow.area() <= 1 )
            {
                int cols = backproj.cols, rows = backproj.rows, r = (MIN(cols, rows) + 5)/6;
                trackWindow = Rect(trackWindow.x - r, trackWindow.y - r,
                                   trackWindow.x + r, trackWindow.y + r) &
                              Rect(0, 0, cols, rows);
            }

  //              if( backprojMode )
    //                cvtColor( backproj, image, COLOR_GRAY2BGR );
            ellipse( image, trackBox, Scalar(0,0,255), 3, CV_AA );
        }
    //}
    //else if( trackObject < 0 )
    //    paused = false;

    if( selectObject && selection.width > 0 && selection.height > 0 )
    {
        Mat roi(image, selection);
        bitwise_not(roi, roi);
    }

    imshow( "CamShift Demo", image );
    imshow( "Histogram", histimg );

    /*char c = (char)waitKey(10);
    if( c == 27 )
    {    ros::shutdown();
}
    switch(c)
    {
    case 'b':
    {    backprojMode = !backprojMode;
        break;
}        
case 'c':{
        trackObject = 0;
        histimg = Scalar::all(0);
        break;}
    case 'h':{
        showHist = !showHist;
        if( !showHist )
            destroyWindow( "Histogram" );
        else
            namedWindow( "Histogram", 1 );
        break;}
    case 'p':{
        paused = !paused;
        break;}
    default:
        ;
    }*/






//Display the image using OpenCV
//cv::imshow(WINDOW, image);
//Add some delay in miliseconds. The function only works if there is at least one HighGUI window created and the window ...
(more)