Reputation: 59
I have written the following program to split the image1 in three channels and then add the image2 to the blue channel of image1. I am using code blocks compiler and it's not showing any error but when I execute it the command prompt shows a runtime error and force closes my program. Can someone tell me what's wrong with my program? here is a link to the screenshot of the error I get https://dl.dropboxusercontent.com/u/13916799/Capture4.JPG
using namespace std;
using namespace cv;
void addImages(Mat &image1,Mat &image2,Mat &result)
{
result.create(image1.size(),image1.type());
vector<Mat> planes;
split(image1,planes);
planes[0] += image2;
merge(planes,result);
}
int main()
{
Mat image1 = imread("C:\\castle.jpg",CV_LOAD_IMAGE_UNCHANGED);
Mat image2 = imread("C:\\rain.jpg",CV_LOAD_IMAGE_UNCHANGED);
Mat result;
addImages(image1,image2,result);
namedWindow("vOut",CV_WINDOW_AUTOSIZE);
imshow("vOut",result);
waitKey(0);
destroyAllWindows();
}
Upvotes: 0
Views: 560
Reputation: 1255
you can't add a one channel image to a three channel image,
planes[0] += image2;
you could find your error message in arithm.cpp
else if( !checkScalar(src2, src1.type(), kind2, kind1) )
CV_Error( CV_StsUnmatchedSizes,
"The operation is neither 'array op array' (where arrays have the same size and the same number of channels), "
"nor 'array op scalar', nor 'scalar op array'" );
add the image2 to the blue channel of image1? I don't quite get it.
split image2 and add them with the same channel, type, size and so on...
Upvotes: 2
Reputation: 6090
The error states: Size of input argument do not match
To resolve this error check the following:
I would guess that the error lies in your imread call for image2.
You read the image with the CV_LOAD_IMAGE_UNCHANGED
this could load an image in rgb, bgr, rgba [...] format, all with more than one channel.
To read an image with as Grayscale (one channel, try: CV_LOAD_IMAGE_GRAYSCALE
)
Check that all your images (and planes) have the right dimension and your Code should work.
Upvotes: 1