我有一个 cv::Mat
A
,它有 CV_32F
。但是它包含整数值,例如 1,2....100。我想形成一个与 A
大小相同的掩码。
但是如果 A(x,y) 不等于 5(比方说),掩码必须包含零。 如果 A(x,y) 等于 5(比方说),掩码必须包含一个。
我想稍后将其用作 ROI。
最佳答案
// you will have a much simpler construct,
// this is just for demonstration
Mat_<float> A(3,3); mf << 1,5,5,2,5,5,1,2,3;
// now use a simple MatExpr to get a mask:
Mat mask = (A == 5);
// show results:
cerr << A << endl;
cerr << mask << endl;
------------------------------
[1, 5, 5;
2, 5, 5;
1, 2, 3]
[0, 255, 255;
0, 255, 255;
0, 0, 0]
关于c++ - 比较 OpenCV Mat 与标量元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26776045/