Android Question OpenCV Face detection / Camera Orientation

gezueb

Active Member
Licensed User
Longtime User
Hi, I am trying to adapt CPJordi's example facedetection8, but in portrait mode. So far, i have not been able to change the code to show the face upright. The picture is always shown sideways. Thanks for help!
 

gezueb

Active Member
Licensed User
Longtime User
Hi, I am trying to adapt CPJordi's example facedetection8, but in portrait mode. So far, i have not been able to change the code to show the face upright. The picture is always shown sideways. Thanks for help!
Okay, no response, obviously it does not work. Solution: I rewrote it to use camera2 library!
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Just seen it now, I'm not very active in the forum lately due to work and familiar issues.
Okay, no response, obviously it does not work.
This is not a logical reasoning at all, and in my opinion, a bit of bad education.
I gently invite you not to use my lib anymore, you won't be charged anything.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Sorry, JordiCP, please dont take it personally at all. My post was not directed at you! I asked the community a specific question and did not get an answer, its as simple as that. I therefore had to search for a workaround and found one. Doubts about my education should be directed to my parents, but they are long gone!
All the best to you for familiy and work issues and a golden Indian summer! :)
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
OK:
I could not make the camera library get a preview or take pictures in portrait mode. It works perfectly in landscape, but on my four different phones and pads it would not give an upright preview in portrait mode but tilting the picture by either 90 degrees right or left. Maybe I did something wrong or left out a parameter, that's why I posted my starting question three weeks ago. Scanning through forums like stackexchange and others I found out that other developers had this issue too. The problem is not in JordiCPs excellent wrapper, but in the underlying intrinsic Android classes. I refer to posts like this one:

So I converted my code to use the camera2 library where the camera orientation is no issue. There is an example for this library here:

I am open to any correction, particularly if someone found out how to get a portrait preview with the original camera lib.
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
OK:
I could not make the camera library get a preview or take pictures in portrait mode. It works perfectly in landscape, but on my four different phones and pads it would not give an upright preview in portrait mode but tilting the picture by either 90 degrees right or left. Maybe I did something wrong or left out a parameter, that's why I posted my starting question three weeks ago. Scanning through forums like stackexchange and others I found out that other developers had this issue too. The problem is not in JordiCPs excellent wrapper, but in the underlying intrinsic Android classes. I refer to posts like this one:

So I converted my code to use the camera2 library where the camera orientation is no issue. There is an example for this library here:

I am open to any correction, particularly if someone found out how to get a portrait preview with the original camera lib.

can you post your work around code?
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
The code is well dispersed in the app, so I send you the whole app as an example. It simulates Hogwarts Fat Lady, detects motion, asks the person to look into the camera, detects a face and frames it and then tries to recognize the person using tensorflow lite. Obviously the last part will not give you reasonable results, as it is trained to recognize me, my wife and my dog. As the zipped file is to large to upload here, I will add a link to the dropbox :
Have fun!
 
Upvote 0

yzhy-mail

Member
The code is well dispersed in the app, so I send you the whole app as an example. It simulates Hogwarts Fat Lady, detects motion, asks the person to look into the camera, detects a face and frames it and then tries to recognize the person using tensorflow lite. Obviously the last part will not give you reasonable results, as it is trained to recognize me, my wife and my dog. As the zipped file is to large to upload here, I will add a link to the dropbox :
Have fun!
Hi ,gezueb
I downloaded the example and tested it .But cann't run it on my phone.
It always crashed in this line:93
"TFLite.Initialize(" ", 224, "faces.tflite", "faces.txt")"
I donn't konw where is the issue.
Maybe you can give some help .
Thank you !
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Sorry, I am in a hospital, no b4a available. But maybe you can tell me what the exception tells you. This statement initializes the tensorflow light recognition. Many things can go wrong like sdk version, file access problems etc. without crash particulars its impossible to guess.
 
Upvote 0

roberto64

Active Member
Licensed User
Longtime User
Hi, the example I queso error

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
ok - model file is present in assets-foilder
java.lang.RuntimeException: Error initializing TensorFlow!
at com.tillekesoft.tensorflowlite.TensorflowWrapper$1.run(TensorflowWrapper.java:53)
at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:784)
Caused by: java.io.FileNotFoundException: faces.tflite
at android.content.res.AssetManager.nativeOpenAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:865)
at com.tillekesoft.tensorflowlite.TensorFlowImageClassifier.copyToCacheFile(TensorFlowImageClassifier.java:181)
at com.tillekesoft.tensorflowlite.TensorFlowImageClassifier.openAssetFile(TensorFlowImageClassifier.java:169)
at com.tillekesoft.tensorflowlite.TensorFlowImageClassifier.loadModelFile(TensorFlowImageClassifier.java:82)
at com.tillekesoft.tensorflowlite.TensorFlowImageClassifier.create(TensorFlowImageClassifier.java:58)
at com.tillekesoft.tensorflowlite.TensorflowWrapper$1.run(TensorflowWrapper.java:47)
... 4 more
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Difficult to guess whats wrong. However, maybe the file copy into the asset folder is not yet finished when the TFLite.Initialize("", 224, "faces.tflite", "faces.txt") is called. faces.tflite is 2 MBytes so it takes a little moment and copy time depends on the phone. Maybe you should use a resumable sub and "wait for" to copy, a sleep command or a loop to check if all the files are there ("faces.tflite, faxes.txt and the cascade file) before tflite is is initialized. Check with sleep 5000 after the copy, thats the easiest way to find out whats not working. If that works, you can always find a more elegant solution.
 
Upvote 0
Top