Why does setTo not work (assertion failed)?

noctilux

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!

uchar

나는 오류가 꽤 명확하다고 생각합니다 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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why and how does this work?

분류에서Dev

OpenCV calibrateCamera() Assertion failed

분류에서Dev

Mysterious Assertion Failed popup

분류에서Dev

Why does pkill not work with rofi?

분류에서Dev

Why does sudo not work with curl?

분류에서Dev

Why does remove(x) not work?

분류에서Dev

Why does this angularjs directive not work?

분류에서Dev

Why does this rename operation not work?

분류에서Dev

Why does this type of inheritance work?

분류에서Dev

Why does this C code not work in JavaScript?

분류에서Dev

Why does this command work for logging script output?

분류에서Dev

Why NodeJS KeepAlive does not seem to work as expected?

분류에서Dev

Why does this C code not work in JavaScript?

분류에서Dev

Why does `kill %jobnumber` not work on stopped jobs?

분류에서Dev

Why does the first assert work, but not the second?

분류에서Dev

Why does this CURL work in PHP but not in the shell

분류에서Dev

Why does strcat not work with empty string in C?

분류에서Dev

Why does the wildcard * not work when changing directories?

분류에서Dev

Why does the following code only work with GridLayout?

분류에서Dev

Why does Docker "ancestry" API command not work?

분류에서Dev

Why does my bubble sort method not work?

분류에서Dev

Why my cron Job does not work?

분류에서Dev

Why does my xdotool key command not work?

분류에서Dev

Why does command injection not work in this example?

분류에서Dev

why piping pwd and echo does not work?

분류에서Dev

flutter : Failed assertion 드롭 다운

분류에서Dev

Failed Assertion 'url! = null': is not true Error

분류에서Dev

Why does $scope.$watch work but $scope.$watchCollection does not?

분류에서Dev

Why Does `'ln -s /directory 'D:'` Work Like It Does?