Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!

Mason Buchanan

Greenhorn
+ Follow
since Apr 16, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
4
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mason Buchanan

Steven Letson wrote:
Let me know if this works for you. If so, we can dig deeper into the diff between your code and this.



@SteveLetson

Alright, so seeing as though your code used a lambda expression to implement the analyzer within the bindAllCameraUseCases() method, would I have to do the same to achieve the same result with my code? Which would also mean basically restructuring the program as a whole. My confusion in the OP was if there was a flawed/missing line(s) within the analyze() method that prevented any data from being acquired by it. That's the reason why I aim to maintain the structure that I have within the OP is because I followed the documentation to the T, and didn't see the as someone who did something similar using Google ML Kit and CameraX as well, except they had used a custom model instead of a base model.

The only thing I will be adding to this minimal version is code to label each object. Also, just to confirm "D/DebugActivity: detectedObjects.size=1" does mean that onSuccess has returned an object list size and is therefore acquiring images passed by the camera preview?
3 days ago
@JoeMcMillan Unfortunately not, this thread pertains to the question asked in the OP. I will see what I can do to help within your thread,
3 days ago

Joe McMillan wrote:@StevenLetson, I enabled webcam for my camera on the emulator through advanced settings, but it's still showing a blank black screen for me. I also tried running it on a different API 30 device, but still no luck. Also, what may be a reason that cameraX doesn't work on Android Studio? Thanks.



Hi Joe,

I would recommend you run the program on a device that this application was written for. When launching on the device, allow your camera permission to be used in the application.

As far as if CameraX not working, I'd recommend writing an application solely with CameraX preview, then using this StackOverflow question and answer in resolving the black screen issue as I used to face the same issue. Hope this works!
4 days ago
@StevenLetson

Your code does indeed work! The onSuccess method logs; "D/DebugActivity: detectedObjects.size=1" within my Logcat, which confirms that the application is carrying out its intended purpose of detecting objects, right? Which makes me wonder why my code in the OP isn't doing the same. Would you happen to know why?
4 days ago
@StevenLetson First of all, I just want to thank you so much for taking your time out and writing out a minimal version of the program that uses the same components. Upon seeing your response, at first I was unclear whether I was supposed to create a new class or create a new project so I ended up doing the latter; starting a new project altogether. From there, I had used the code written for the "public final class DebugActivity" in the Main Activity. For the most part, I was able to write out the code smoothly. the only errors I got were in the onCreate method, as displayed with the double slashes:



Aside from this, everything else in your code had transitioned smoothly! These are the only errors I had received and I sincerely hope you can clear the air as to how or why to resolve them. Hopefully, when this is said and done, we can move forward on seeing what was wrong with my code.

Oh, and you also wanted to know where Line 27 from my OP was from. I was actually following a specific StackOverflow question not too different from my situation, except this user used a custom model, whereas I used a base model. I figured that some similarity in writing our code would solve my problems. Which shouldn't have been the case.

Edit: to specifically mention Steven Letson on his reply at the beginning of my message
6 days ago

Tim Moores wrote:

Paul Clapham wrote:Line 27 produces an empty array and the following lines process all of the entries in that empty array, i.e. they always do nothing.


Good catch! Line 27 should be deleted, and line 28 should use "detectedObjects" instead of"results".



Alright, so I've deleted Line 27. I've then proceeded to turn Line 28 into;



After doing this, I then proceeded to run the application and try to "Log.d("TAG", "onSuccess " + detectedObjects.size());" the onSuccess method on line 25, which still prints "D/TAG: onSuccess0", which still means the return object list size is 0, right? Seeing as though Line 27 no longer exists to produce an empty array, is there any reason why the following lines aren't processing the formerly empty arrays?

Once again, I must thank you both for your help thus far! It truly means a lot, considering this is the first real progress I have made in a while with this problem. However, the question still stands.
1 week ago

Paul Clapham wrote:

Mason Buchanan wrote:So update! I Log.d(..) the following code to see if it was throwing null like so;



I don't know what you mean by "throwing null". The code you have there logs the message if the mediaImage variable is NOT null. If it was null then yes, nothing would happen. But it isn't, so your posted code is all being run. (Which answers Tim's question.)

As for your actual problem, I don't know anything about that topic so I can't give you any help there, sorry.



You're absolutely right. I should not have typed "throwing null" knowing that != meant that if the mediaImage wasn't null. My apologies. Thank you for clearing it up! Hopefully somebody will be able to clarify. By any chance, would you be able to know where I could turn to for any sort of guidance in resolving this? Especially since I've tried StackOverflow and Reddit.
1 week ago
So update! I Log.d(..) the following code to see if it was throwing null like so;



In which, the console did print D/TAG: mediaImage is throwing null.

So the application launches just fine. But considering that mediaImage is null, my question now stands to why mediaImage is showing up empty when I'm following verbatim from official Google ML documentation.
1 week ago
@Tim Moores The reasoning for placing mediaImage != null there is done according to this exact step of the Google ML Documentation, which is needed to prepare the input image. I should probably clarify that this I am fairly new to Java programming, and so I was following the documentation in order to follow this through to its end result. I'm unsure of whether mediaImage != is indeed null, is there any method I should use to double check?

Because I was simply following the documentation, I must ask; would the line of if (mediaImage != null) { ..} mean that if mediaImage wasn't null, then the code should continue on to what I've typed within the braces? and if null references to the fact that mediaImage is empty, how would I resolve this?

1 week ago
I'm currently working on an Android application (using Java on Android Studio) that captures images from a live camera preview and analyzes/labels them. The two components of the application use a CameraX preview as well as a Google ML Kit Object Detection Documentation.

While the CameraX preview works absolutely fine, the Google ML Kit is where I encounter some challenge. My Google ML Kit Object Detection does not carry out its intended purpose; detecting objects. To further add to my confusion, no errors are being detected, before and after running the program. All I know for sure is that the application does not process the image within my analyze() method, and therein lies the problem.

How do I know this? I added some Log.d("TAG", "onSuccess " + detectedObjects.size()); within my onSuccess method to determine the size of the returned object list, only for the Android Studio logcat to print D/TAG: onSuccess0 upwards of up to 20 times within the span of several seconds of running the application. Even within the 4 steps outlined within the aforementioned Google ML Kit documentation, Step 2: Prepare the input image & Step 3: Process the image are where I'm instructed to write the following code.

Rather than bombard this post with the entire page of code, I've chosen to provide the analyze() method where the image preparing and processing take place;


While I understand that this may seem like an Android question, the Java code is the focus of the issue. The problem indeed lies with what exactly is wrong with the code that prevents images from being acquired by the aforementioned method. I have been scouring the the internet for weeks for any guidance on how to further resolve this issue. Any further information needed to supplement this question will be provided upon request!
1 week ago
@CampbellRitchie thank you very much! I'm so new to the site it means a lot that you were able to redirect my question to the proper place it needs to be asked.

@ClaudeMoore also, I thank you so much for your detailed response! I have been scouring the internet for even a semblance of guidance in resolving this question. I should probably add that I'm quite new to developing Java (and coding in general), and so my guidance in creating this application was through using this CameraX documentation for implementing a CameraX preview as well as this aforementioned Google ML Kit documentation on object detection. Would it be possible to isolate the two elements of image acquiring and object detection within the same MainActivity.java class?

Also, the application does acquire images within the camera preview. According to my attempt in debugging onSuccess within the analyze() method, the application does not return any object list size (as evidenced by the Logcat printing D/TAG: onSuccess0) allowing me to arrive at that conclusion. Once again, any further guidance would be greatly appreciated, even though I understand your expertise doesn't lay fully within Android development!
2 weeks ago
I'm currently working on a mobile application using CameraX and Google ML Kit written in Java (on Android Studio). The purpose of the application is to detect objects with a real time camera preview. I was able to build the base CameraX Preview which works absolutely fine. After doing this, I implemented ML Kit using this guide aptly titled "Detect and track objects with ML Kit on Android" (base model option) to detect objects in successive frames within the application.

However, upon running the application, it launches on my device and the camera preview continues to work but the application does not carry out its intended effect of actually detecting objects and displaying it on my screen. In an attempt to resolve it, I debugged the onSuccess within my process method using Log.d(..) in order to determine the size of the returned object list. However, upon running the application, the Android Studio logcat had printed D/TAG: onSuccess0 upwards of up to 20 times within several seconds of running the application. Would this mean that the application is not detecting any objects? This has bugged me since I had followed the documentation exactly.

Here is the necessary code within my MainActivity:


Any resolution or even indication as to why the ML Kit Object Detector isn't working would help tons. Any additional information needed to supplement this question will be provided upon request.
2 weeks ago