0

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?

Community
  • 1
  • 1
DrTarr
  • 922
  • 2
  • 15
  • 34

2 Answers2

0

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.

Community
  • 1
  • 1
DrTarr
  • 922
  • 2
  • 15
  • 34
-1

Try this:

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

Be careful with the size of the mask.

Marcel
  • 269
  • 2
  • 15
  • No luck, compile error: "error: no matching function for call to 'cv::Mat::copyTo(cv::Mat&, cv::Rect)'". – DrTarr Dec 09 '16 at 16:30