Ask Your Question
0

How to load an IPlImage from Android ImageView

asked 2013-10-17 10:23:43 -0600

bunta gravatar image

updated 2013-10-17 15:06:47 -0600

berak gravatar image

I have an image displayed in android ImageView. Now I want to convert that image to openCV IPlImage, how to do that. I am not reading the image file from file system because I want to draw on android imageView and width and height of the image displayed on imageView and original image in the storage will be different.

And the solution I used is-

IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-10-17 14:06:33 -0600

Moster gravatar image

updated 2013-10-17 14:44:44 -0600

Please dont use IplImage on android. IplImage is deprecated in c++ and java.

Here is some code that should basically work. Please test it:

imView.buildDrawingCache();
Bitmap bmap = imView.getDrawingCache();
Bitmap bmapCv = bmap.copy(Bitmap.Config.ARGB_8888, true);
Mat imgMat = new Mat();
Utils.bitmapToMat(bmp32, imgMat);

IplImage for javacv (not tested)

IplImage img = IplImage.create(cvSize(width, height) IPL_DEPTH_8U, 4);
Bitmap bmap = imView.getDrawingCache();
Bitmap bmapCv = bmap.copy(Bitmap.Config.ARGB_8888, true);
bitmap.copyPixelsToBuffer(img.getByteBuffer());
edit flag offensive delete link more

Comments

Mat image = Highgui.imread("/sdcard/TVguide/Detection/detected.jpg"); hows this ?

bunta gravatar imagebunta ( 2013-10-17 14:13:20 -0600 )edit

any idea about equivalent of Utils.bitmapToMat(bmp32, imgMat); in javaCV

bunta gravatar imagebunta ( 2013-10-17 14:17:58 -0600 )edit

This does not even fit your question. You were asking how to extract a Mat from an ImageView. Now you just want to load an image with imread? This is something totally different. Also no, Im not familiar with javaCv

Moster gravatar imageMoster ( 2013-10-17 14:25:50 -0600 )edit

javacv wraps iplimages instead of cv::Mat. this is more a shootout between the 'official' opencv java wrappers and javacv

berak gravatar imageberak ( 2013-10-17 14:35:14 -0600 )edit

Moster.. sorry for that.. yes I admit thats a wrong point of asking ..@berak.. does it mean I can comfortably use IplImage in javaCv ..

bunta gravatar imagebunta ( 2013-10-17 14:37:55 -0600 )edit

@bunta, maybe your question needs a 'javacv' tag, and some explanation, what you're trying to do ?

berak gravatar imageberak ( 2013-10-17 14:38:12 -0600 )edit

ok I realized one thing that even IplImage.asCvMat is there to use

bunta gravatar imagebunta ( 2013-10-17 14:40:17 -0600 )edit

if you're using javacv, you have to use iplimages. maybe you want to rephrase your question on how to transform pixels from an imageview to a javacv iplimage ( and i can't help you here, not using javacv )

berak gravatar imageberak ( 2013-10-17 14:42:00 -0600 )edit

thanks @berak for notifying the point of converting pixel to IplImage..I'll look into it

bunta gravatar imagebunta ( 2013-10-17 14:44:06 -0600 )edit

I found something that might work with IplImage. Check my edit.

Moster gravatar imageMoster ( 2013-10-17 14:49:23 -0600 )edit

Question Tools

Stats

Asked: 2013-10-17 10:23:43 -0600

Seen: 5,382 times

Last updated: Oct 17 '13