Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV ROI on Real time camera

I am trying to set ROI in real time camera and copy a picture in the ROI. However, I tried many methods from Internet but it is still unsuccessful. Part of my code is shown below:

 while(!protonect_shutdown)
        {
         listener.waitForNewFrame(frames);   

         libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir];    

         cv::Mat(ir->height, ir->width, CV_32FC1,  ir->data).copyTo(irmat);
         Mat img = imread("button.png");
         cv::Rect r(1,1,100,200);
         cv::Mat dstroi = img(Rect(0,0,r.width,r.height));
         irmat(r).convertTo(dstroi, dstroi.type(), 1, 0);
         cv::imshow("ir", irmat / 4500.0f);

        int key = cv::waitKey(1);

        protonect_shutdown = protonect_shutdown || (key > 0 && ((key & 0xFF) == 27)); 

        listener.release(frames);
     }

My real time camera can show the video normally.

I used rectangle(irmat,r,Scalar(0,255,0),2); in my code, the rectangle can be shown successfully in the real time camera. But the picture is unsuccessful.

And no bugs in my program, but the picture cannot be shown in the ROI. Does anyone have some ideas? Any help is appreciate.