Sample face detection does not work

1,201 views
Skip to first unread message

Tand

unread,
Sep 9, 2011, 3:33:55 PM9/9/11
to android-opencv
Hi,
I try to run the sample face detection, but it does not work. I see
t:he next error in the log:

09-09 19:20:55.050: ERROR/CV_CAP(313): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600

I have also tried my Android phone (Samsung Galaxy S), but it does
neither work. The screen remains black.

Any suggestions?

Raul Carvente

unread,
Sep 9, 2011, 5:22:50 PM9/9/11
to android...@googlegroups.com

What version of Android do you configure? Did you add correctly the project? Try to update your project variables in the properties file.

Tand

unread,
Sep 10, 2011, 8:21:44 AM9/10/11
to android-opencv
Android version 2.2 (SDK 8). I have run the sample "Sample - face-
detection", which included in OpenCV+Android SDK. I have not modified
anything, and run it as it is.

On 9 sep, 23:22, Raul Carvente <brachial...@gmail.com> wrote:
> What version of Android do you configure? Did you add correctly the project?
> Try to update your project variables in the properties file.

Leonid Beynenson

unread,
Sep 12, 2011, 5:53:19 PM9/12/11
to android-opencv
Hello Tand,

Could you attach more lines from android log?
Did you recompile OpenCV source code?

It seems to me that either you use incompatible versions of several
OpenCV libraries (it is possible if you tried to recompile OpenCV), or
camera of your android device passes to OpenCV functions image in some
format which is not close to the standard YUV.4.2.0 format (probably,
Android log contain some messages about it).

Sincerely yours,
Leonid Beynenson.

Tand

unread,
Sep 13, 2011, 7:25:23 AM9/13/11
to android-opencv
Hi Leonid,

Here are more lines from Android log.

BTW. The example "Tutorial 1 Basic - 0. Android Camera" and "Tutorial
1 Basic - 1. Add OpenCV" work fine. I have also used JavaCV in other
project. Are they maybe in conflict?

Best regards.


09-13 11:06:11.333: INFO/AndroidRuntime(305): NOTE: attach of thread
'Binder Thread #3' failed
09-13 11:06:11.333: INFO/ActivityManager(61): Start proc
org.opencv.samples.fd for activity org.opencv.samples.fd/.FdActivity:
pid=312 uid=10039 gids={1006}
09-13 11:06:12.684: INFO/Sample::Activity(312): Instantiated new class
org.opencv.samples.fd.FdActivity
09-13 11:06:12.705: INFO/Sample::Activity(312): onCreate
09-13 11:06:12.763: INFO/Sample::SurfaceView(312): Instantiated new
class org.opencv.samples.fd.FdView
09-13 11:06:12.813: DEBUG/dalvikvm(312): Trying to load lib /data/data/
org.opencv.samples.fd/lib/libopencv_java.so 0x44ede300
09-13 11:06:12.984: DEBUG/dalvikvm(312): Added shared lib /data/data/
org.opencv.samples.fd/lib/libopencv_java.so 0x44ede300
09-13 11:06:13.174: INFO/Sample::FdView(312): Loaded cascade
classifier from /data/data/org.opencv.samples.fd/app_cascade/
lbpcascade_frontalface.xml
09-13 11:06:13.873: INFO/Sample::SurfaceView(312): surfaceCreated
09-13 11:06:13.895: DEBUG/dalvikvm(312): Trying to load lib /data/data/
org.opencv.samples.fd/lib/libopencv_java.so 0x44ede300
09-13 11:06:13.895: DEBUG/dalvikvm(312): Shared lib '/data/data/
org.opencv.samples.fd/lib/libopencv_java.so' already loaded in same CL
0x44ede300
09-13 11:06:13.914: DEBUG/CAMERA_ACTIVITY(312): Library name:
libopencv_java.so
09-13 11:06:13.914: DEBUG/CAMERA_ACTIVITY(312): Library base address:
0x81000000
09-13 11:06:13.943: DEBUG/CAMERA_ACTIVITY(312): Libraries folder
found: /data/data/org.opencv.samples.fd/lib/
09-13 11:06:13.943: DEBUG/CAMERA_ACTIVITY(312):
CameraWrapperConnector::connectToLib: folderPath=/data/data/
org.opencv.samples.fd/lib/
09-13 11:06:13.943: ERROR/CAMERA_ACTIVITY(312): ||
libnative_camera_r2.2.2.so
09-13 11:06:13.943: ERROR/CAMERA_ACTIVITY(312): ||
libnative_camera_r2.3.3.so
09-13 11:06:13.943: DEBUG/CAMERA_ACTIVITY(312): try to load library
'libnative_camera_r2.2.2.so'
09-13 11:06:13.993: DEBUG/CAMERA_ACTIVITY(312): Loaded library '/data/
data/org.opencv.samples.fd/lib/libnative_camera_r2.2.2.so'
09-13 11:06:14.004: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::initCameraConnect(0x813e65a1, 0, 0x228ba8, 0x0)
09-13 11:06:14.045: DEBUG/CameraHardwareStub(34): initHeapLocked:
preview size=320x240
09-13 11:06:14.164: DEBUG/OpenCV_NativeCamera(312): Instantiated new
CameraHandler (0x813e65a1, 0x228ba8)
09-13 11:06:14.164: INFO/OpenCV_NativeCamera(312): initCameraConnect:
[picture-format=jpeg;picture-size=320x240;picture-size-
values=320x240;preview-format=yuv422sp;preview-frame-rate=15;preview-
size=320x240;preview-size-values=320x240]
09-13 11:06:14.164: DEBUG/OpenCV_NativeCamera(312): Supported Cameras:
(null)
09-13 11:06:14.164: DEBUG/OpenCV_NativeCamera(312): Supported Picture
Sizes: 320x240
09-13 11:06:14.164: DEBUG/OpenCV_NativeCamera(312): Supported Picture
Formats: (null)
09-13 11:06:14.164: DEBUG/OpenCV_NativeCamera(312): Supported Preview
Sizes: 320x240
09-13 11:06:14.164: DEBUG/OpenCV_NativeCamera(312): Supported Preview
Formats: (null)
09-13 11:06:14.164: DEBUG/OpenCV_NativeCamera(312): Supported Preview
Frame Rates: (null)
09-13 11:06:14.173: DEBUG/OpenCV_NativeCamera(312): Supported
Thumbnail Sizes: (null)
09-13 11:06:14.173: DEBUG/OpenCV_NativeCamera(312): Supported
Whitebalance Modes: (null)
09-13 11:06:14.173: DEBUG/OpenCV_NativeCamera(312): Supported Effects:
(null)
09-13 11:06:14.173: DEBUG/OpenCV_NativeCamera(312): Supported Scene
Modes: (null)
09-13 11:06:14.173: DEBUG/OpenCV_NativeCamera(312): Supported Focus
Modes: (null)
09-13 11:06:14.173: DEBUG/OpenCV_NativeCamera(312): Supported
Antibanding Options: (null)
09-13 11:06:14.173: DEBUG/OpenCV_NativeCamera(312): Supported Flash
Modes: (null)
09-13 11:06:14.183: DEBUG/Camera(312): app passed NULL surface
09-13 11:06:14.244: INFO/Sample::SurfaceView(312): surfaceCreated
09-13 11:06:14.244: INFO/Sample::SurfaceView(312): before
mCamera.getSupportedPreviewSizes()
09-13 11:06:14.244: ERROR/CAMERA_ACTIVITY(312): calling
(*pGetPropertyC)(0x228f78, 2)
09-13 11:06:14.244: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::getProperty(2)
09-13 11:06:14.274: INFO/Sample::SurfaceView(312): Starting processing
thread
09-13 11:06:14.284: DEBUG/dalvikvm(312): Trying to load lib /data/data/
org.opencv.samples.fd/lib/libopencv_java.so 0x44ede300
09-13 11:06:14.284: DEBUG/dalvikvm(312): Shared lib '/data/data/
org.opencv.samples.fd/lib/libopencv_java.so' already loaded in same CL
0x44ede300
09-13 11:06:14.313: INFO/Sample::SurfaceView(312): after
mCamera.getSupportedPreviewSizes()
09-13 11:06:14.323: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::setProperty(0, 320.000000)
09-13 11:06:14.323: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::setProperty(1, 240.000000)
09-13 11:06:14.346: DEBUG/dalvikvm(312): Trying to load lib /data/data/
org.opencv.samples.fd/lib/libopencv_java.so 0x44ede300
09-13 11:06:14.346: DEBUG/dalvikvm(312): Shared lib '/data/data/
org.opencv.samples.fd/lib/libopencv_java.so' already loaded in same CL
0x44ede300
09-13 11:06:14.483: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::applyProperties()
09-13 11:06:14.483: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::applyProperties()
09-13 11:06:14.483: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::applyProperties(): before previousCameraHandler-
>closeCameraConnect
09-13 11:06:14.668: INFO/ActivityManager(61): Displayed activity
org.opencv.samples.fd/.FdActivity: 3403 ms (total 65352 ms)
09-13 11:06:14.693: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::applyProperties(): after previousCameraHandler-
>closeCameraConnect
09-13 11:06:14.693: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::applyProperties(): before initCameraConnect
09-13 11:06:14.693: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::initCameraConnect(0x813e65a1, 0, 0x228ba8, 0x4763ecac)
09-13 11:06:14.703: DEBUG/CameraHardwareStub(34): initHeapLocked:
preview size=320x240
09-13 11:06:14.723: INFO/ActivityManager(61): Displayed activity
com.android.launcher/com.android.launcher2.Launcher: 65405 ms (total
65405 ms)
09-13 11:06:14.823: DEBUG/OpenCV_NativeCamera(312): CameraHandler
destructor is called
09-13 11:06:14.975: DEBUG/OpenCV_NativeCamera(312): Instantiated new
CameraHandler (0x813e65a1, 0x228ba8)
09-13 11:06:14.975: INFO/OpenCV_NativeCamera(312): initCameraConnect:
Setting paramers from previous camera handler
09-13 11:06:14.975: DEBUG/CameraHardwareStub(34): initHeapLocked:
preview size=320x240
09-13 11:06:14.983: DEBUG/Camera(312): app passed NULL surface
09-13 11:06:14.993: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::applyProperties(): after initCameraConnect,
handler=0x22d378
09-13 11:06:15.124: ERROR/CAMERA_ACTIVITY(312): calling
(*pGetPropertyC)(0x22d378, 0)
09-13 11:06:15.124: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::getProperty(0)
09-13 11:06:15.124: ERROR/CAMERA_ACTIVITY(312): calling
(*pGetPropertyC)(0x22d378, 1)
09-13 11:06:15.124: DEBUG/OpenCV_NativeCamera(312):
CameraHandler::getProperty(1)
09-13 11:06:15.124: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:15.124: ERROR/CV_CAP(312): CvCapture_Android::grabFrame:
NO new frame
09-13 11:06:15.124: ERROR/Sample::SurfaceView(312): mCamera.grab()
failed
09-13 11:06:15.124: INFO/Sample::SurfaceView(312): Finishing
processing thread
09-13 11:06:15.323: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:15.533: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:15.673: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:15.773: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:15.873: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:15.994: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:16.104: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:16.213: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:16.314: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:16.444: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:16.542: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:16.683: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:16.803: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:16.954: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.064: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.174: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.283: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.383: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.493: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.625: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.733: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.853: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:17.964: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:18.104: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:18.204: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:18.313: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:18.434: INFO/OpenCV_NativeCamera(312): ### Camera FPS ###
[30] Frames, 7.43 FPS
09-13 11:06:18.434: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:18.563: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:18.734: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:18.844: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600
09-13 11:06:18.954: ERROR/CV_CAP(312): ERROR reading YUV buffer:
width=320, height=240, size=115200, receivedSize=153600


On 12 sep, 23:53, Leonid Beynenson <leonid.beynen...@itseez.com>
wrote:

Leonid Beynenson

unread,
Sep 27, 2011, 9:33:21 AM9/27/11
to android...@googlegroups.com
Hello Tand,

I'm really sorry for the delay with the response.
Unfortunately, I have to say that the reason of the error is most probably in strange behavior of your device --- see explanation below.

Could you write more details what device do you use?

The reason of the error is as follows: the Android camera module gives to OpenCV camera module a buffer which is longer than required. I investigated your log and found why Android camera system sends to OpenCV such a long buffer. The reason is as follows: the default preview format of your Android device is yuv422sp, whereas OpenCV works with the default preview format  yuv420sp

See the log line

09-13 11:06:14.164: INFO/OpenCV_NativeCamera(312): initCameraConnect: [picture-format=jpeg;picture-size=320x240;picture-size-values=320x240;preview-format=yuv422sp;preview-frame-rate=15;preview-size=320x240;preview-size-values=320x240]

It is a bit strange, since almost all Android devices use yuv420sp as a default preview format, the format is recommended by Google; moreover, from Android 2.3 this format support is a must for Android devices.

When OpenCV connects to Android camera, it asks Android about supported preview formats, and tries to set the preview format to YUV420SP. But, as we can see from the log line


09-13 11:06:14.164: DEBUG/OpenCV_NativeCamera(312): Supported Preview Formats: (null) 

your device does not return what preview format it supports.  This is a bit strange behavior too, and I'm not sure, that this device behavior is compliant with Google rules. See the specification of java method Camera.Parameters.getSupportedPreviewFormats --- "This method will always return a list with at least one element." (I quote this sentence from Android Java specs, but, as far as I know, Android Java code for camera in this case consists of java wrappers of the same inner C++ functions)

So OpenCV camera module cannot set the camera preview format.

So, when your device sends to OpenCV camera module an image from the camera, the OpenCV module cannot receive the image, and, unfortunately, this is a correct behavior, since the image has wrong format indeed.
Reply all
Reply to author
Forward
0 new messages