QR code detection issue from photo using openCV - android

I am currently working on an android application, that should be able to detect a QR code from a picture taken. It is not necessary to decode the QR code because it's only needed to calibrate the camera.
I am using openCV and when I tried to detect the QR code from the original downloaded picture of the QR code it works fine. That's the code I used:
bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.qrcodemitzeugs);
Mat img =new Mat();
Utils.bitmapToMat(bitmap,img)
Mat points= new Mat();
QRCodeDetector detector=new QRCodeDetector();
boolean data = detector.detect(img, points);
But when I try the same Code on a photo taken with my smartphone's camera, the QR code doesn't get detected. I searched for a solution and found that maybe the contrast wasn't high enough so converted the picture into binary using following code:
Imgproc.cvtColor(img,img2,Imgproc.COLOR_BGR2GRAY);
Imgproc.threshold(img2,img2,100,255,Imgproc.THRESH_BINARY);
It returned the whole image in black and white but still the QR code wasn't detected.
Did I do something wrong or is there a solution for this problem?
One of the images i used
I had to resize the picture before uploading it

So I solved my problem, by resizing the Mat to a max of 1200x1200. Apparently the OpenCV QRCodeDetector can only handle Mats between ca. 85x85 and ca. 1200x1200, in which the QR Code itself has to have at least a size of ca. 80x80. I tested this with the image of the original QR Code, which had a size of 600x600. I resized it until the QR Code wasn't detected anymore.

Related

Revert Barcode object to image in Android

I am getting Barcode(com.google.android.gms.vision.barcode) object from a physical sales card via camera. Is there a way to convert it back to a image using gms:play-services-vision library?
I think you will get barcode value in a string. you may try to below code
TextView tv = (TextView)findViewById(R.id.textview);
tv.setText(bitmapstring);
tv.buildDrawingCache();
ImageView img = (ImageView)findViewById(R.id.imageview);
img.setImageBitmap(tv.getDrawingCache());
Seems like there's no way of doing that by using the play-services-vision library. My first thought would be to take a screen capture of the preview of the camera before actually reading the barcode, but let's suppose you cannot do that.
If you have the actual data and the format of the barcode you can use ZXing to generate back the barcode image.
Here's an example of how to do it: Generate barcode image in Android application

Got wrong data by ImageReader when reading from a video?

I am writing an app to grab every frame from a video,so that I can do some cv processing.
According to Android `s API doc`s description,I should set Mediaplayer`s surface as ImageReader.getSurface(). so that I can get every video frame on the callback OnImageAvailableListener .And it really work on some device and some video.
However ,on my Nexus5(API24-25).I got almost green pixel when ImageAvailable.
I have checked the byte[] in image`s Yuv planes,and i discover that the bytes I read from video must some thing wrong!Most of the bytes are Y = 0,UV = 0,which leed to a strange imager full of green pixel.
I have make sure the Video is YUV420sp.Could anyone help me?Or recommend another way for me to grab frame ?(I have try javacv but the grabber is too slow)
I fix my question!!
when useing Image ,we should use getCropRect to get the valid area of the Image.
forexample ,i get image.width==1088 when I decode a 1920*1080 frame,I should use image.getCropImage() to get the right size of the image which will be 1920,1080

Saved video as input instead of Camera in android

I've implemented an android app that implements the CvCameraListener interface. In the onCameraFrame(Mat inputFrame) method I process the captured inputFrame from the camera.
Now to my problem: Is there a way that I can use a saved video file on my phone as an input instead of getting the frames directly from camera? That means I would like to have a video file input frame by frame in Mat format.
Is there a possible way to do that?
Thanks for your answers
though it is not tested and I don't have much experience in OpenCV on Android. Still, you can try like this:
//[FD : File descriptor or path.]
Bitmap myBitmapFrame;
MediaMetadataRetriever video_retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(FD);
myBitmapFrame = retriever.getFrameAtTime(..);
}
catch(...
:
Utils.bitmapToMat(myBitmapFrame, myCVMat);
You may have to implement some callback system as you can work with only OpenCV after it is initialized. Also, you can convert frame number to time-code.
Good Luck and Happy Coding. :)

zxing not found exception in android

Hello everyone,
If any one of you can help me this. I am using zxing to decode barCode image, but it returns com.google.zxing.NotFoundException, don't know why. The same image gets decoded via Intent provided to zxing, but not when I use it to decode from image file.
The code that I am using is below :
mMultiFormatReader = new MultiFormatReader();
mMultiFormatReader.setHints(null);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(path)));
Result result = mMultiFormatReader.decodeWithState(bitmap);
I don't think it's exactly the same image, since you can't have it scan a file by Intent. I assume you mean that you can scan the image off your screen fine, but the image itself does not decode.
That's just life, really. Some images won't happen to decode. But you may try TRY_HARDER mode or use a different binarizer to see if that works.

Android OpenGL ES read PHONE inconsistant with EMULATOR

Hey,
i wrote a small application, a client application which receives images from a server, and then display them on a rotating cube using openGL ES.
this works just fine in the emulator, but on real phone SGS , blank white images displayed instead.
what could be the problem ???
the photos are saved using
fos = openFileOutput(i+".jpg",MODE_WORLD_READABLE);
and then read and converted to Bitmap using
File myImage= context.getFilesDir();
String imgPath=myImage.getAbsolutePath();
BitmapDrawable bmd = new BitmapDrawable(imgPath+"/"+face+".jpg");
bitmap[face]= bmd.getBitmap();
The Rendering Code used is same as supposed in Example 6a: Photo-Cube , under MYGLRenderer.java
Thanks in Advance.
This sounds somewhat similar situation I faced some time ago. Reason was that I didn't resize Bitmap to size of power of two before sending it to GL context.
https://gamedev.stackexchange.com/questions/10829/loading-png-textures-for-use-in-android-opengl-es1

Categories

Resources