I am new to OpenCV and just doing a basic RGB color filter. I was doing this by testing each pixel, but that's inefficient. So I tried Core.inRange
but that returns a mask (black and white) and I need a colored Mat
. Here is what I currently have:
// frame is input, out is output
Scalar minValues = new Scalar(RFrom, GFrom, BFrom);
Scalar maxValues = new Scalar(RTo, GTo, BTo);
Mat mask = new Mat();
Core.inRange(frame, minValues, maxValues, mask);
Core.bitwise_and(frame, mask, out);
When I run it, I get:
.CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.2) /Users/jason/Projects/openpnp/opencv/opencv/opencv-3.4.2/modules/core/src/arithm.cpp:225: error: (-209: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 function 'binary_op' ]
This is because the mask
updated by inRange
has type CV_8UC1
but the frame has type CV_8UC3
. What can I do to fix this?