如何正确使用bitwise_and?

时间:2018-07-11 10:27:37

标签: android opencv opencv4android bitwise-and

您好,我正在尝试从道路图片中检测出白线和黄线,就像在本教程https://github.com/naokishibuya/car-finding-lane-lines中所做的那样,但是我使用Java而不是Python

image = new Mat(3, 3, CvType.CV_32S, Scalar.all(0));
white_mask = new Mat(3, 3, CvType.CV_32S);
yellow_mask = new Mat(3, 3, CvType.CV_32S);
mask = new Mat(3, 3, CvType.CV_32S);
masked = new Mat(3, 3, CvType.CV_32S);

// white color mask

lower = new Scalar(200, 200, 200);
upper = new Scalar(255, 255, 255); 
Core.inRange(image, lower, upper, white_mask);
// inRange(Mat src, Scalar lowerb, Scalar upperb, Mat dst)

// yellow color mask

lower = new Scalar(190, 190, 0);
upper = new Scalar(255, 255, 255);
Core.inRange(image, lower, upper, yellow_mask);
// combine the mask
Core.bitwise_or(white_mask, yellow_mask, mask);
//bitwise_or(Mat src1, Mat src2, Mat dst)
Core.bitwise_and(mask, image, masked);
//bitwise_and(Mat src1, Mat src2, Mat dst)

但是当我使用 bitwise_and

时,在执行期间出现错误
 Caused by: CvException [org.opencv.core.CvException: cv::Exception: /build/master_pack-android/opencv/modules/core/src/arithm.cpp:225: 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 void cv::binary_op(cv::InputArray, cv::InputArray, cv::OutputArray, cv::InputArray, void (* const*)(const uchar*, size_t, const uchar*, size_t, uchar*, size_t, int, int, void*), bool, int)
    ]
        at org.opencv.core.Core.bitwise_and_1(Native Method)
        at org.opencv.core.Core.bitwise_and(Core.java:989)

如果您可以帮助我理解该错误以及如何解决该问题,我将是OpenCV的新手。

0 个答案:

没有答案