How to set ROI in OpenCV?

后端 未结 2 1644
不思量自难忘°
不思量自难忘° 2020-12-01 14:40

I have two images, the first one smaller than the other. I need to copy the second image on the first image. To do so, I need to set the ROI on the first one, copy the secon

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 15:13

    This is the code I used. I think the comments explain it.

    /* ROI by creating mask for the parallelogram */
    Mat mask = cvCreateMat(480, 640, CV_8UC1);
    // Create black image with the same size as the original
    for(int i=0; i(Point(i,j)) = 0;
    
    // Create Polygon from vertices
    vector approxedRectangle;
    approxPolyDP(rectangleVertices, approxedRectangle, 1.0, true);
    
    // Fill polygon white
    fillConvexPoly(mask, &approxedRectangle[0], approxedRectangle.size(), 255, 8, 0);                 
    
    // Create new image for result storage
    Mat imageDest = cvCreateMat(480, 640, CV_8UC3);
    
    // Cut out ROI and store it in imageDest
    image->copyTo(imageDest, mask);
    

    I also wrote about this and put some pictures here.

提交回复
热议问题