I'm failing miserably at something I think it should be very easy to
achieve. I'm importing a Bitmap from a .jpg file I have in drawable
converting it to mat and then trying to change it to a grayscale
image, converting it back to bitmap to display.
This is the code I use:
package com.greven.test.contour;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
public class ContourTestActivity extends Activity {
ImageView iv;
Mat mMat, mAux;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv = (ImageView) findViewById(R.id.my_image);
mMat = new Mat();
mAux = new Mat();
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.squares);
mMat = Utils.bitmapToMat(bmp);
Imgproc.cvtColor(mMat, mAux, Imgproc.COLOR_RGB2GRAY, 0);
Utils.matToBitmap(mMat, bmp);
iv.setImageBitmap(bmp);
}
}
I've tried with different space colors and I always get this error as
long as I try to convert it to Gray.
The error I get is this:
10-14 04:10:38.626: ERROR/AndroidRuntime(3343): Caused by: CvException
[org.opencv.core.CvException: /home/andreyk/OpenCV2/trunk/
opencv_2.3.1.b2/modules/imgproc/src/color.cpp:2834: error: (-215) scn
== 3 || scn == 4 in function void cv::cvtColor(const cv::_InputArray&,
const cv::_OutputArray&, int, int).
Anyone knows what am I doing wrong?
Thank you.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en