gpt4 book ai didi

c++ - 输入参数的 bitwise_and 大小不匹配

转载 作者:太空狗 更新时间:2023-10-29 20:55:54 25 4
gpt4 key购买 nike

我正在尝试使用 bitwise_and 以根据阈值排除图像的所有其余部分,但是当我尝试时它给出:

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/schirrel/Github/opencv/opencv-2.4.10/modules/core/src/arithm.cpp, line 1021 terminate called after throwing an instance of 'cv::Exception' what(): /home/schirrel/Github/opencv/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

我的代码是

Mat src, src_gray, dst;

int main()
{
src = imread("robosoccer.jpg", 1);
cvtColor(src, src_gray, CV_BGR2GRAY);
threshold(src_gray, dst, 150, 255, 1);
Mat res;
bitwise_and(src, dst, res);
imshow("AND", res);
("hold", res);
waitKey(0);
return (0);
}

你能帮帮我吗?

最佳答案

你应该使用:

bitwise_and(src_gray, dst, res);

错误意味着 srcdst 两个图像维度不相等,因为它们的 channel 数不同。

你也可以这样写:

Mat res = src_gray & dst;

或:

Mat res = src_gray.clone();
res.setTo(Scalar(0), ~dst);

如果你需要彩色图像,你可以像@sturkmen suggested那样做

bitwise_and( src, src, res, dst );

或:

Mat res = src.clone();
res.setTo( Scalar( 0, 0, 0 ), ~dst);

关于c++ - 输入参数的 bitwise_and 大小不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34664539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com