Here is my code
package com.deneme.deneme;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img=(ImageView) findViewById(R.id.pic);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.p26);
Mat imgToProcess=Utils.bitmapToMat(bmp);
//******
//right here I need to convert this imgToProcess to grayscale for
future opencv processes
//******
Bitmap bmpOut = Bitmap.createBitmap(imgToProcess.cols(),
imgToProcess.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(imgToProcess, bmpOut);
img.setImageBitmap(bmpOut);
}
Roman
package com.deneme.deneme;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img=(ImageView) findViewById(R.id.resimBir);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.p26);
Mat imgToProcess=Utils.bitmapToMat(bmp);
Mat imgToProcessGray = new Mat();
Imgproc.cvtColor(imgToProcess,
imgToProcessGray,Imgproc.COLOR_BGR2GRAY);
Bitmap bmpOut = Bitmap.createBitmap(imgToProcessGray.cols(),
imgToProcessGray.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(imgToProcessGray, bmpOut);
img.setImageBitmap(bmpOut);
try direct drawable->Mat method, Mat imgToProcess =
Utils.loadResource(context, R.drawable.p26);
Roman
package com.deneme.deneme;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import org.opencv.android.Utils;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img=(ImageView) findViewById(R.id.picOne);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.n);
Mat imgToProcess=Utils.bitmapToMat(bmp);
Mat imgToProcessGray = new Mat(imgToProcess.cols(),
imgToProcess.rows(), CvType.CV_8UC1, new Scalar(0));
Imgproc.cvtColor(imgToProcess,
imgToProcessGray,Imgproc.COLOR_RGB2GRAY,4);
What abt if you use ..
Imgproc.cvtColor(imgToProcess,
imgToProcessGray,Imgproc.COLOR_RGB2GRAY,1);
means destination channel no is 1.....if you think problem is related
to channel
On Dec 12, 1:47 pm, Tuncay <tuncaycakma...@gmail.com> wrote:
> Hi again,
> Roman and Hardik thanks for your replies, but I am still getting a
> failed result at the end.
> The closest code to success is this so far... And the result image is
> here for you to see(http://www.rudral.com/result.jpg). I think the
cvtColor(src, dst, COLOR_RGB2GRAY) is not working, neither is
cvtColor(src, dst, COLOR_RGB2GRAY,1), neither using COLOR_RGBA2GRAY...
The only thing I managed to work was:
capture.retrieve(mat1, Highgui.CV_CAP_ANDROID_GREY_FRAME)
Imgproc.cvtColor(mat1, mat2,Imgproc.COLOR_GRAY2RGBA, 4)
but then I get a 4 channel gray image... so how can I get a single
channel gray image?? actually, how can I get a single channel at all
(e.g green channel)? I tried extractChannel and didn't work!
Mat img= Highgui.imread(Utils.exportResource(context,
R.drawable.imageToLoad), Highgui.CV_LOAD_IMAGE_GRAYSCALE);
After your processes are finished with this image, you must save this
mat variable and then load it again to display with imageview.
Thanks for your replies.
capture.retrieve(mat, Highgui.CV_CAP_ANDROID_GREY_FRAME);
Imgproc.cvtColor(mat, dst, Imgproc.COLOR_GRAY2RGBA, 4);
This is working but I am getting a 4 channel grayscale which I think
it's not necessary, a single channel grayscale mat might be easier and
faster for image processing, isn't it?
Doing this is not working for me:
capture.retrieve(mat, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
cvtColor(mat, dst, COLOR_RGB2GRAY);
OR
cvtColor(nat, dst, COLOR_RGB2GRAY,1);// neither using
COLOR_RGBA2GRAY...
so, how can one get a single channel grayscale mat? and what about
extracting one color channel of a mat?
In order to get a single channel I tried the following but didn't
work:
capture.retrieve(mat, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
Core.extractChannel(mat,dst, 1);
Is there any other way to achieve this?