Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

[Debugging] Provided data element number (1) should be multiple of the Mat channels count (4)

Hi there, I am attempting to threshold a ROI of an image which contains a specific color yellow. So my objective is to threshold that specific ROI and then lay it back to the original image and then display the new image again. This new image will thus be the original image with that little ROI threshold-ed. I am trying out this this set of code which I have no idea if it will work yet. The idea is to set the ROI region in the original image with the threshold-ed colors at its corresponding pixel coordinates:

            Mat source = new Mat();     
    Utils.bitmapToMat(drawnBitmap, source);

    Mat roi = source.submat(100, 700, 100, 700);
    Log.w("roi type", String.valueOf(roi.type()));
    Mat mBGR= new Mat();
    Mat mBGRThres = new Mat();
    Imgproc.cvtColor(roi, mBGR, Imgproc.COLOR_RGBA2BGR,0);
    Core.inRange(mBGR, new Scalar(0, 255, 255), new Scalar(0, 255, 255), mBGRThres); 

    Mat thresholded= source.clone();
    for(int j=0; j<thresholded.rows(); j++)  { 
        for(int i=0;i<thresholded.cols(); i++) {
            if(i>=100 && i<=700 && j>=100 && j<=700){                   
                thresholded.put(j, i,mBGRThres.get(j-100, i-700) );
            }
        }

        }
    double color[]= source.get(300, 300); // rgb at the coordinate of the image 300, 300
    Log.w("RGB", String.valueOf(color[0]) + String.valueOf(color[1]) +String.valueOf(color[2]));

    Highgui.imwrite("Threshold.jpg", thresholded);

    Bitmap bmp = Bitmap.createBitmap(thresholded.rows(),
            thresholded.cols(), Config.ARGB_8888);
    Utils.matToBitmap(thresholded, bmp);

I tried compiling but the logcat throws me the following set of errors:

01-14 22:20:33.340: E/AndroidRuntime(6722): java.lang.UnsupportedOperationException: Provided data element number (1) should be multiple of the Mat channels count (4) 01-14 22:20:33.340: E/AndroidRuntime(6722): at org.opencv.core.Mat.put(Mat.java:2496)

So what I gather from this set of error is that the channels are different, the mBGRThres has (1) channel and thresholded has (4) channels. Is there any way to perform cvtColor or any other methods to align their channels? Correct me if my understanding of the error msg is warped. Thanks!

I develop on the Android platform in Eclipse using OpenCV249