简体   繁体   中英

Copying bottom portion of cv::Mat to another cv::Mat

I am only interested in performing HoughLinesP on the bottom half of an image, for performance reasons, so I would like to copy the bottom portion of one image to another image of the same size. It is important to maintain image size because I need to keep the lines detected relative to the original image.

I have tried to adapt this solution with the following code:

int startpoint{ 240 };
cv::Mat houghlinesmat{ image.size(), image.type(), cv::Scalar(0) };
houghlinesmat.setTo(0);
image.copyTo( houghlinesmat(cv::Rect(0,
                                     startpoint,
                                     image.cols,
                                     image.rows - startpoint)) );

However, I always receive a copyTo assert error similar to this example. However, it does not appear to me to be an issue of being 1 row or column off. It seems more that I cannot copy a cv:rect smaller than the output without error. Any idea what's missing?

Found some direction to the final solution here , see last comment.

Adapted:

image( cv::Rect(0,
                startpoint,
                image.cols,
                image.rows -
                startpoint)).copyTo(houghlinesmat(cv::Rect(0,
                startpoint,
                image.cols,
                image.rows -
                startpoint)));

A bit messy looking in the end but exactly what I wanted. Essentially I wasn't specifying both the source and destination regions, so the size didn't match.

Try this:

image.copyTo( houghlinesmat, cv::Rect(0,
                                     startpoint,
                                     image.cols,
                                     image.rows - startpoint));

Be careful with the size of the mask.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM