문제

I want to blend a color (RGB) image with a greyscale image in OpenCV 2. I am currently getting runtime errors and the cause seems to be that I am using different types for each image pixel. e.g. the color image is CV_8U. My code:

cv::Mat copy;
    image.copyTo(copy);
    cv::cvtColor(copy, copy, CV_BGR2GRAY);
    threshold(copy, copy, 0, 255,3 );
    addWeighted( image, 0.5f, copy, 0.5f, 0.0,image);

The error is in the addWeighted function. I am unsure how to blend these two images.

도움이 되었습니까?

해결책

After cvtcolor, your grayscale image is in one channel. Change it back to three channel after you have performed threshold. So, between threshold and addWeighted, add the statement:

cv::cvtColor ( copy, copy, CV_GRAY2BGR );

Also, I am not sure what you want to achieve. If you want to just extract the regions that are white, you are better off using the cv::bitwise_and.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top