我是一名有用的助手,可以为您翻译文本。
这是错误信息:。
我有一张黑白图像和一张同样大小的彩色图像。我想将它们合并成一张图像,在黑白图像为黑色的地方显示黑色,在黑白图像为白色的地方显示与彩色图像相同的颜色。
以下是C++代码:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(){
Mat img1 = imread("frame1.jpg"); //coloured image
Mat img2 = imread("framePr.jpg", 0); //grayscale image
imshow("Oreginal", img1);
//preform AND
Mat r;
bitwise_and(img1, img2, r);
imshow("Result", r);
waitKey(0);
return 0;
}
这是错误信息:。
OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array') in binary_op, file /home/voja/src/opencv-2.4.10/modules/core/src/arithm.cpp, line 1021
terminate called after throwing an instance of 'cv::Exception'
what(): /home/voja/src/opencv-2.4.10/modules/core/src/arithm.cpp:1021: error: (-209) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array' in function binary_op
Aborted (core dumped)
copyTo
将复制掩码中所有值!=0
的像素。我认为你需要将r
初始化为零。 - AntoniocopyTo
在realloc时将所有元素设置为零。但是,出于清晰起见,我也更喜欢将其初始化为零 :) - kiranpradeep