I'm working on eye detection project and I have trained my own model using Tensorflow Library, I have now the Tensorflow lite model.
I followed the documentation proposed by Tensorflow for how to integrate custom model MLKit firebase on the Android platform.
This is CustomModelActivity.java that I followed
https://github.com/firebase/snippets-android/blob/a7be1d9b6208d112d1bacbfff937c32c219124b5/mlkit/app/src/main/java/com/google/firebase/example/mlkit/CustomModelActivity.java#L127-L128
I tried to implement this function by setting the image on imageview and I have tried to convert it to bitmap
But I have encountered some issue ( false predictions ) on an image from the dataset.
I have posted many questions about this problem but I didn't get any answer.
I would like now to load the image from my gallery and get it, My question is:
How can I implement the last function getYouInputImage() ?
private Bitmap getYourInputImage() {
// This method is just for show
return Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8);
}
Related
I am creating an android app to run on Google Glass Enterprise Edition 2 that does Real-time Face Recognition. I am using Camera X as my Camera API and TensorFlow Lite (TFLite) as my classification model. However, the TFLite model input requires ByteBuffer which I am unable to convert into from the image retrieved from CameraX.
How do I get my Image from CameraX into ByteBuffer class for my TFLite Model?
Camera X Image Analysis: Reference
val imageAnalysis = ImageAnalysis.Builder()
.setTargetResolution(Size(640, 360))
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.build()
imageAnalysis.setAnalyzer(AsyncTask.THREAD_POOL_EXECUTOR, ImageAnalysis.Analyzer { imageProxy ->
val rotationDegrees = imageProxy.imageInfo.rotationDegrees
val mediaImage = imageProxy.image
if (mediaImage != null) {
val image = InputImage.fromMediaImage(mediaImage, rotationDegrees)
/* Classify the Image using TensorFlow Lite Model */
}
})
TensorFlow Model Sample Code
val model = FaceRecognitionModel.newInstance(context)
// Creates inputs for reference.
val inputFeature0 = TensorBuffer.createFixedSize(intArrayOf(1, 224, 224, 3), DataType.FLOAT32)
inputFeature0.loadBuffer(byteBuffer)
// Runs model inference and gets result.
val outputs = model.process(inputFeature0)
val outputFeature0 = outputs.outputFeature0AsTensorBuffer
// Releases model resources if no longer used.
model.close()
Try using the TensorImage class from the TensorFlow Lite Support Library.
Roughly, you can follow these steps.
Convert the Image object into Bitmap. There should be other Stackoverflow questions on how to do this (e.g., this answer)
Create a TensorImage object from the Bitmap object using TensorImage.fromBitmap() factory.
Call getBuffer() method on the TensorImage object to get the underlying ByteBuffer.
You might also want to do some image pre-processing, in case the image from CameraX doesn't exactly match the format expected by the model. For this, you can explore the ImageProcessor utility.
I have made some findings and I applied these to help shorten my problem.
The image I have gotten from CameraX is in YUV. I have trained my model in RGB in 224X224. To suit my issue, I first convert the image to RGB Bitmap, then crop it into 224X224. Afterwards convert Bitmap to ByteBuffer.
As for my TFLite Model, the TFLite model managed to accept the converted RGB ByteBuffer image and process it. Returning back
TensorBuffer.
I need to display the YouTube's video thumbnail image for every video searched or featured. I just need the syntax and method to implement it in my java swing application.
You can load the thumbnails directly via web request. Take a look at How do I get a YouTube video thumbnail from the YouTube API?
EDIT
Here are some sample links:
https://img.youtube.com/vi/<video-id>/default.jpg
https://img.youtube.com/vi/<video-id>/hqdefault.jpg
- or -
https://img.youtube.com/vi/<video-id>/maxresdefault.jpg
Assuming you get the SearchListResponse from youtube v3 data api. Now you can easily fetch the thumb url using following code.
SearchListResponse response = // data fetched from yt data api.
java.util.List<SearchResult> searchResultList = response.getItems();
for (SearchResult sr : searchResultList) {
String thumburl = sr.getSnippet().getThumbnails().getDefault().getUrl();
//for high resolution you can use: sr.getSnippet().getThumbnails().getHigh().getUrl();
}
related links. https://developers.google.com/youtube/v3/docs/search/list
I am developing an andorid app which post some photo on Facebook, at the same time I want to calculate the number of likes of that photo from my android app.
For information -
I am using Facebook SDK and I have successfully logged in Facebook account and posted the image.
The method which post image is below
private void PublishImage()
{
Bitmap image = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
//Here we set all the required parameters to share the image and build that
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.setCaption("Testing Sharing Feature through java")
.build();
//Now we share the PhotoContent by adding the properties in instance of SharePhotoContent
share = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();
//Now we use share API to share the image
ShareApi.share(share,null);
}
How to calculate the number of likes of posted photo with java instead of using Graph API Explorer manually ?
I don't think you can do that without the graph API. Once you call ShareApi.share (), there is actually a graph API request which uploads the photo, and you will get likes from various platforms, your app has no way of knowing how many likes have been posted
I have created an activity captures an image through Camera and now I have the image in Bitmap format which I want to pass to this plugin class from here:
The function looks like this:
public void process(MarvinImage imageIn, MarvinImage imageOut, MarvinAttributes attrOut, MarvinImageMask mask, boolean preview) {
Now how do I pass these arguments?
It first asks for MarvinImage so how can I convert my Bitmap to MarvinImage? And what are rest of the arguments?
Please help.
Unfortunately, the android compatible version of Marvin was not released yet. It's under development. You can follow the project releases on its Freecode page.
If you want to understand how Marvin works, what are these arguments, take a look at the Tutorials available on the project website.
I have a problem, I can only create thumbnails of local video files but not of a remote url, here is my code:
bmThumbnail = ThumbnailUtils.extractThumbnail(ThumbnailUtils.createVideoThumbnail("http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", MediaStore.Video.Thumbnails.MINI_KIND), 50, 50);
I hope you can help me,
regards
christian
I suppose there is no easy way to build the thumbnail without actually downloading the video locally.
So if your question is 'Can I get a thumbnail without having to download the full video?', I'd say...no.
Otherwise, once you have downloaded the video locally, then I guess you can perfectly use ThumbnailUtils.createVideoThumbnail(...) by giving the path to the downloaded file.
I also have the same problem - but what can I say from my tests:
The problem occurs only on android >2.3
in android 2.0 -> 2.3 You can use just
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail( videoUrl, MediaStore.Video.Thumbnails.MINI_KIND);
I hope someone explain what change is on android 4. it doesn't work
I have no problem generating thumbnails from remote videos with the following code:
final Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail( videoUrl, MediaStore.Video.Thumbnails.MINI_KIND );
You don't have to wrap an extractThumbnail() call around it