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