I am just learning OpenCV and, since I have some experience with Matlab's logical indexing, I was really interested to see the matrix method setTo. My initial attempt doesn't work though, and I can't work out why, so I'd be very grateful for your help!
I have a Mat containing image data, and want to set all values greater than 10 to zero. So, I did:
Mat not_relevant = abs(difference - frame2) > 10;
difference = difference.setTo(0, not_relevant);
This however gives me:
OpenCV Error: Assertion failed (mask.empty() || mask.type() == CV_8U) in
cv::Mat::setTo, file
C:\builds\2_4_PackSlave-win32-vc12-shared\opencv\modules\core\src\copy.cpp, line 347
I have tried converting not_relevant, difference and frame2 before doing this using, e.g.:
frame2.convertTo(frame2, CV_8UC1);
but that did not fix the error, so I'm not sure what else I could try. Does anyone have any idea what might be wrong?
Thank you for your help!
나는 오류가 꽤 명확하다고 생각합니다 CV_8U
. 마스크 이미지의 유형은 .
not_relevent
그레이 스케일 로 변환해야합니다 .
Mat not_relevant = abs(difference - frame2) > 10;
cv::cvtColor(not_relevant, not_relevant, CV_BGR2GRAY);
difference = difference.setTo(0, not_relevant);
왜 convertTo가 여기서 작동하지 않습니까?
CV_8U
(또는 CV_8UC1
)은 uchar 값의 한 채널이있는 이미지 유형입니다 .
convertTo
이미지의 채널 수를 변경할 수 없습니다.
따라서 하나 이상의 채널이있는 이미지를 사용으로 변환 CV_8U
하는 convertTo
것은 작동하지 않습니다. 자세한 설명은 이 답변 을 확인하십시오 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다