Error with function copyTo() and mask
RogerAylagas opened this issue · comments
Enviroment
Ubuntu 18.04
OpenCV
C++
Content
The objective of the code is masking the image. To do so I created a mask, invert it and then use the function copyTo() to copy the pixels that are in white in the mask.
Code
capR >> frameR;
cvtColor(frameR, imGrayR, CV_RGB2GRAY);
cv::Mat mask2 = cv::Mat::zeros(frameR.size(), frameR.type());
cv::ellipse(mask2, cv::Point(650,700), cv::Size(300,400),
180,0,180, cv::Scalar(255, 255, 255),-1,8,0);
cv::Mat inv_mask = cv::Scalar::all(255) - mask2;
imGrayR.copyTo(masked_imGrayR, inv_mask);
imshow("masked image",masked_imGrayR);
waitKey(0);
Error
But while executing an error occur:
OpenCV Error: Assertion failed (mask.depth() == 0 && (mcn == 1 || mcn == cn)) in copyTo, file /home/roger/opencv/modules/core/src/copy.cpp, line 381
terminate called after throwing an instance of 'cv::Exception'
what(): /home/roger/opencv/modules/core/src/copy.cpp:381: error: (-215) mask.depth() == 0 && (mcn == 1 || mcn == cn) in function copyToAborted (core dumped)
I have detected that the issue is in the line 6, in the function copyTo()
Can anyone help me with this issue??
Thank you
I had the same problem, how did you solve it ?