Currently I'm working on a android program using Mobile Vision. I am using the "TextRecognizer" class and one of the methods is .detect(Frame frame). Right now I have a image I want to input into it, however, the image is the file type "Bitmap". I have tried to convert it to "Frame" by casting it but that hasn't worked. If anyone has any suggesting it would be much appreciated.
Use the setBitmap method in the Frame.Builder class:
Frame outputFrame = new Frame.Builder().setBitmap(myBitmap).build();
Related
What I'm curious is simple.
We created video calling functionality using mobile technology on WebRTC.
In addition, I would like to use the OpenCV library to add face detection during video calls.
To implement this function, it is necessary to convert Bitmap to WebRTC I420Frame.
Is there a way?
Using libYuv (https://chromium.googlesource.com/libyuv/libyuv/) would likely be the best way. Once you determine what type the bitmap is (rgb, bgr, argb, etc...), you can pass it to libYuv and it will convert it to i420 for you in an efficient way.
You could also run the calculations yourself if you really wanted to but you wouldn't get the arm specific performance calls that libYuv would do for you.
Using libYuv https://chromium.googlesource.com/libyuv/libyuv/
The following code works:
size_t file_size = frame.width() * frame.height() * 3;
std::unique_ptr<uint8_t[]> res_rgb_buffer2(new uint8_t[file_size]);
webrtc::ConvertFromI420(frame, webrtc::VideoType::kRGB24, 0,
res_rgb_buffer2.get());
now res_rgb_buffer2 contains a pointer for raw BMP data. you can save it in a file but you need to write file header first. the latter part can be found here.
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
do you know if the video as a source for the canvas drawImage() method is supported on Android?
The goal is to display the video and to select one moment to take a picture of this moment in a frame (drawImage (video,0,0), return canvas)). Do you think it is doable?
Thanks!
There is an approach in Android that will return you a bitmap for a given point in a video, which may give you want you need (or needed as this is an old question!):
MediaMetadataRetriever (https://developer.android.com/reference/android/media/MediaMetadataRetriever.html#getFrameAtTime%28long,%20int%29)
getFrameAtTime
Added in API level 10
Bitmap getFrameAtTime (long timeUs,
int option)
Call this method after setDataSource(). This method finds a representative frame close to the given time position by considering the given option if possible, and returns it as a bitmap. This is useful for generating a thumbnail for an input data source or just obtain and display a frame at the given time position.
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. :)
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