Face detection not working for Front Camera - java

So basically, i have this code,
if(mCamera.getParameters().getMaxNumDetectedFaces()==0)
{
System.out.println("Face detection not avaliable");
}
else
{
System.out.println("Max faces: " + Integer.toString(mCamera.getParameters().getMaxNumDetectedFaces()));
}
mCamera.setFaceDetectionListener(new FaceDetectionListener() {
#Override
public void onFaceDetection(Face[] faces, Camera camera) {
// TODO Auto-generated method stub
System.out.println("Face detection callback called." + Integer.toString(faces.length));
}
});
After calling mCamera.startFaceDetection();, the callback is called, everything works as normal. However, if I change cameras, the same code results in the callback never being called. The getMaxNumDetectedFaces, returns 35 for both cameras, so I assume its supported on the front camera. I can change the camera back and forth, calling this code each time, and it will work for the back camera but not the front one.
Is there anything else I might be doing wrong?

Is it possible that the quality of the camera that's not working (the front one, right?) Isn't accurate enough for the face detection to work? The camera's image may be too noisy for the face detector to work. There are lot of other variables that could be hindering this.
Also doing a search for front camera, it looks like the front camera's points may be mirrored. This is described in: http://developer.android.com/reference/android/hardware/Camera.Face.html
I hope this helps.

Is there a way to check if the camera is being read? Java has always had some issues in registering web cams etc.... Perhaps try to make sure you can see images with the webcam.
Btw, if you want any further help, we will need to know more about the code. library etc....

This code will return the id of your Front facing camera, for others you can change camera.CameraInfo:
private int findFrontFacingCamera() {
int cameraId = -1;
// Search for the front facing camera
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++) {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
Log.d("FaceDetector", "Camera found");
cameraId = i;
break;
}
}
return cameraId;
}
I had the code which worked on my Gallaxy tablet but it wouldnt call the take foto and as a result wouldnt call face detection in other devices, so after searching for a while I found this solution which worked. I added the following code in the class where takePicture is called :
camera.startPreview();

You can use Webcame for capturing image from webcam. it automatically detects webcam so no need to extra configuration for webcam. it also support more than one webcam at a time.

Related

How to get the frame rate in android exoplayer programmatically?

I want to get the live stream frame rate using android exoplayer programmatically.
I did try following code to get the frame rate.
exo_player.addAnalyticsListener(new AnalyticsListener() {
#Override
public void onTracksChanged(EventTime eventTime, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
if(trackGroups!=null && !trackGroups.isEmpty()){
for(int i=0;i<trackGroups.length;i++){
for(int j=0;i<trackGroups.get(i).length;j++){
float videFrame = trackGroups.get(i).getFormat(j).frameRate;
Log.e("videoFrame",String.valueOf(videFrame));
}
}
}
}
});
but in my code, i can get -1. this is wrong.
Is there a way to get the video frame in exoplayer programmatically?
Are you sure the index you gave to get() as a parameter belongs to a video segment? Maybe iterating the track groups with a for loop like below might help you.
for (i in 0 until trackGroups.length) {
val videoFrame = trackGroups.get(i).getFormat(i).frameRate
Log.i("videoFrame", "$videoFrame")
}

Android OrientationEventListener making to many calls

I have a video on my app and I'm trying to achieve that when the user rotates his device from portrait to landscape the video changes to full-screen.
I'm using OrientationEventListener like this:
orientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
#Override
public void onOrientationChanged(int orientation) {
if (orientation <= 45 && playerManager.isFullscreen()) {
onPlayerFullscreenChange(false); //ORIENTATION_PORTRAIT
} else if (orientation <= 135 && !playerManager.isFullscreen()) {
onPlayerFullscreenChange(true); //ORIENTATION_LANDSCAPE
} else if (orientation <= 225 && playerManager.isFullscreen()) {
onPlayerFullscreenChange(false); //ORIENTATION_PORTRAIT
} else if (orientation <= 315 && !playerManager.isFullscreen()) {
onPlayerFullscreenChange(true); //ORIENTATION_LANDSCAPE
}
}
};
The problem is that this listener gets called so many times that my video can't play normally. The activity ends up going throw the OnCreate multiple times unlike before.
The onOrientationChanged(int orientation) method notifies you everytime the sensor detects a change in the way you are holding the Android device.
It is nearly impossible for a user to hold the device still, thus the onOrientationChanged() gets called multiple times.
What I have understood from your question is that, you only want to display a video in fullscreen when the user holds the device horizontally.
Thus consider angular values of 0-45, 135-255, and 315-360 as VERTICAL.
And, angles between 45-135 and 225-315 as HORIZONTAL.
This will make sense if you give it some thought.
Store the "previous orientation", which you can set to null initially for example, if you use String. Then compare it with the currently detected orientation, if they are not the same, take an action (set video to full screen or vice-versa) and save the current orientation values as "previous orientation".
This problem really comes down to better implementing your algorithm. All the best!

Drawing on photo - when rotating, lose strokes

I am currently using the code here, albeit heavily modified to suit my needs
https://stackoverflow.com/a/28186621/4541217
such as I need to take an image from the camera as well as select from the gallery. I am also zooming the image.
This all works nicely, except for one issue. I lose things when I rotate the device.
I have
bTemp = null;
if(getLastNonConfigurationInstance() != null) {
bTemp = getLastNonConfigurationInstance();
}
in my onCreate, and an override...
#Override
#Deprecated
public Object onRetainNonConfigurationInstance() {
return bTemp;
}
I can make this return the image but I lose all of my stroke information.
From the example, I have tried saving the Uri, the alteredBitmap, the bitmap and the choosenImageView. However, none of these are working. If I take a photo, scribble on it, then before doing anything else, using the alteredBitmap, if I rotate, then I get the first set of strokes. However, nothing after that.
Can anyone help me to keep my stroke information on rotate please?
Learn about the activity lifecycle.
You need to override functions like onPause, onResume, and use the savedInstanceState.
I managed to work it out eventually, so for anyone else that is trying to do the same, here is what I did.
Following on from the example link in my opening post, in order to make it stick while rotating...
in the onRetainNonConfigurationInstance, keep the alteredBitmap. (This is in the Activity)
#Override
#Deprecated
public Object onRetainNonConfigurationInstance() {
return alteredBitmap;
}
then, in the onCreate of the activity...
if(getLastNonConfigurationInstance() != null) {
bmp = (Bitmap)getLastNonConfigurationInstance();
alteredBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
choosenImageView.setNewImage(alteredBitmap, bmp);
}
notice that the "bmp" is what was sent from alteredBitmap, and now alteredBitmap is the new image. This is then passed into the setNewImage in the DrawableImageView.

Program exported from processing 3.1.1 not working on android device

I have make a video player which split the monitor with one side the image captured by the attached camera and the other side a video clip. It operates without error under java mode. When I run the program under android mode, processing reports no error but the sketch is not running on my phone, a pop up window which says
unfortunately, (sketch name) has stopped
shows up.
My code as below.
import processing.video.*;
Movie myMovie;
Capture cam;
void setup() {
size(displayWidth, displayHeight);
myMovie = new Movie(this,"new cctv.mp4");
myMovie.loop();
myMovie.mask(myMovie);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(i,cameras[i]);
}
cam = new Capture(this,cameras[0]);
cam.start();
}
}
void draw() {
if(cam.available()){
cam.read();}
image(cam, 0, 0, displayWidth, displayHeight);
image(myMovie, width/2, 0,displayWidth/2,displayHeight);
}
void movieEvent(Movie m){
m.read();
}
Time to start debugging your code.
The first thing you should try is hooking this up to LogCat so you can actually see the stack trace. Do that right now, as that's going to answer 95% of your question.
If that doesn't give you any information, then I guess you'll have to start adding print statements to see where your code fails.
I am suspicious of this line:
void setup() {
size(displayWidth, displayHeight);
It's generally a bad idea to pass variables into the size() function, especially if you aren't using the settings() function.
I'm also suspicious of the libraries you're importing. Are you sure they work in Android mode? Not all Java libraries automatically work for Android.

GWT infinite scroll with discarding start-of-list results

Looking for a GWT DataGrid component which implements infinite scroll, BUT also makes sure to discard the results no longer visible on the screen : such as the previously loaded results that are not shown anymore.
This is to avoid a memory hog.
I've been trying to find this on Google, but no luck so far.
Please note : I could take a JS library and adapt it to what I need, but I don't think it would work good with GWT's DataGrid component.
Edit: I am interested specifically in an infinite scroll which ALSO discards/releases the topmost results that are not visible (and loads them up as appropriate).
Any ideas ?
As a matter of fact the showcase example has an infinite scrolling CellList. (you can find the code there).
Although this was done with a CellList the same principles should also apply to a DataGrid.
Check out the ShowMorePagerPanel.java file.
Update:
The onScroll function of ShowMorePagerPanel.java will add the new records at the bottom. However you can easily change the behavior:
Something along the lines (not tested tough):
HasRows display = getDisplay();
if (display == null) {
return;
}
boolean loadData = false;
// If scrolling up, change newStart
int oldScrollPos = lastScrollPos;
lastScrollPos = scrollable.getVerticalScrollPosition();
// get the current visible Range
Range currentRange = display.getVisibleRange();
if (oldScrollPos >= lastScrollPos) {
int newStart = Math.max(
currentRange.getStart() - incrementSize,0);
loadData = true;
}
int maxScrollTop = scrollable.getWidget().getOffsetHeight()
- scrollable.getOffsetHeight();
if (lastScrollPos >= maxScrollTop) {
// We are near the end, so increase the page size.
int newPageSize = Math.min(
display.getVisibleRange().getLength() + incrementSize,
display.getRowCount());
loadData = true;
}
if (loadData) {
display.setVisibleRange(newStart, newPageSize);
}

Categories

Resources