OpenCV ROI on Real time camera

asked 2017-04-24 16:41:19 -0600

double gravatar image

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.

edit retag flag offensive close merge delete

Comments

I think problem is at line cv::imshow("ir", irmat / 4500.0f); irmat is a mat with float type and with imshow you have to check rule written in doc :

If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].

add minMaxIdx to find maximum of irmat and used this maximum in convertTo

LBerger gravatar imageLBerger ( 2017-04-24 19:15:59 -0600 )edit

If i donot use cv::imshow("ir", irmat / 4500.0f); my ir information cannot change successfully.;At this moment, my ir information can be shown very well in real time camera. Additionally, I cannot understand why I should used maximum value of mat to set ROI? Could you please explain it more clearly? Thanks in advance

double gravatar imagedouble ( 2017-04-24 20:22:00 -0600 )edit

" But the picture is unsuccessful. " what does it mean? black image? white image?

[Ir 512x424 float. Range is 0.0, 65535.0. try with cv::imshow("ir", irmat /65536.0f);

LBerger gravatar imageLBerger ( 2017-04-25 01:45:43 -0600 )edit

The camera shows nothing about the picture, looks like I didn't set ROI in the camera and I didn't input the picture.

double gravatar imagedouble ( 2017-04-25 12:09:48 -0600 )edit