Android Question Raspberry pi3 Android Things Camera Help

serro efe

Member
Licensed User
Longtime User
Sorry for my bad english (google translate)
Hi!
https://developer.android.com/things/training/doorbell/camera-input.html
Can we encode the application on the link with B4A.
I could not access the camera ID number. How should I follow a path.
Log(jo.RunMethod("getCameraIdList",Null))
Error on line. Other inquiries positive
CameraManager manager =(CameraManager) context.getSystemService(CAMERA_SERVICE);

Hardware access to uart, spi, i2c, "peripheral manager", but access to camera is different i guess.
Here are some events I can not figure out about "getSystemService"

B4X:
    Dim jo As JavaObject = pm
    'Log(jo.RunMethod("getCameraIdList",Null))
    Log(jo.RunMethod("getUartDeviceList", Null))
    Log(jo.RunMethod("getI2sDeviceList", Null))  
    Log(jo.RunMethod("getGpioList", Null))
    Log(jo.RunMethod("getPwmList", Null))
    Log(jo.RunMethod("getI2cBusList", Null))
    Log(jo.RunMethod("getSpiBusList", Null))
 

serro efe

Member
Licensed User
Longtime User
Yes I tested with the standard camera library and I share the log output below.
findCamera
null
1
facing: 2, 0
findCamera
android.hardware.Camera$CameraInfo@13587bb
1
facing: 2, 1

I made @JordiCP's experiments with OpenCV library. I share the log output with it.
JavaCameraView2 examples
How should I follow the path to the new library? Accessing the hardvare will be difficult for me.
can you help me please
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Is the preview size that you are trying to set supported by the device?

Where did you get my lib from?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Hi @JordiCP You sent the library. I'm serif
Hello serif! Sorry, I didn't know your B4A forum user name

Difficult to say if it is due to how this specific camera is seen by the system, or a more obvious thing. I have a raspberry pi3 somewhere but haven't even plugged it yet so I am a bit lost here. The only things I see are:
The code in the link you posted uses the Android camera2 API.
B4A camera lib and JavaCameraView are based in the camera(1) API, which is deprecated, but "in theory" compulsory to be implemented by all vendors, so it should still work if that camera is seen internally as a "normal" Android camera.

Can you post how you initialize it in OpenCV? It seems as if the camera you are using identifies itself as "front-facing". So perhaps you are trying to initialize a back-facing one?
 
Upvote 0

serro efe

Member
Licensed User
Longtime User
Hello @JordiCP
The situation for the front and rear camera does not work the same.
Log output for camera options below

mOpenCvCameraView.Initialize("frameprocessor",P,mOpenCvCameraView.CAMERA_ID_ANY)
JavaCameraViewInitialize java camera
JavaCameraViewTrying to open camera with old open()
JavaCameraViewTrying to open camera with new open(0)
JavaCameraViewCamera #0failed to open: Fail to connect to camera service
mCamera=null

mOpenCvCameraView.Initialize("frameprocessor",P,mOpenCvCameraView.CAMERA_ID_BACK)
JavaCameraViewInitialize java camera
JavaCameraViewTrying to open back camera
JavaCameraViewBack camera not found!
mCamera=null

mOpenCvCameraView.Initialize("frameprocessor",P,mOpenCvCameraView.CAMERA_ID_FRONT)
JavaCameraViewInitialize java camera
JavaCameraViewTrying to open front camera
JavaCameraViewFront camera not found!
mCamera=null

https://www.b4x.com/android/forum/threads/advanced-camera-library-v1-00.9383/
I tested it with the library in there and the result failed.
B4X:
Dim camera1 As AdvancedCamera
...
...
  camera1.CameraBack --failed
  camera1.CameraBack2 --failed
  camera1.CameraFront --failed
  camera1.CameraFront2 --failed
I do not see the connected camera as a normal android camera,camera id constantly turns to -1
https://developer.android.com/things/training/doorbell/camera-input.html
https://developer.android.com/reference/android/hardware/camera2/package-summary.html
I think you are using camera2 API from these codes.


Maybe the problem might be related to the android sdk version, maybe there is another setting to turn the camera on and off
 
Upvote 0

serro efe

Member
Licensed User
Longtime User
@JordiCP, @Erel, do you have an idea? I have tested the camera with the python-OpenCV pair in the raspian system and there is no problem in getting the link and image. All the applications I tested for things worked on my own phone but not on pi3.
Maybe it works. The output for the above code is below for pi3.
B4X:
    Dim p As Phone
    Dim sb As StringBuilder
    sb.Initialize
    p.Shell("pm list features",Null,sb,Null)
    Msgbox(sb.ToString,"ss")
The output about my camera on my phone is below
feature:reqGlEsVersion=0x30000
feature:android.hardware.camera
feature:android.hardware.camera.any
feature:android.hardware.camera.autofocus
feature:android.hardware.camera.flash
feature:android.hardware.camera.front
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Sorry I cant help since I haven't tested anything in raspberry. But it seems quite clear that now it does not find the cam.

Anyway, I am a bit confused: are you connecting a camera to the CSI-2 port or to the USB port?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I tested USB and CSI-2 cameras separately.
My guess is that USB cameras are not seen "directly" by android so perhaps they can work with the raspbian+python+OpenCV example, but it is because there must be built-in support/drivers for them in raspbian.
About the CSI-2, the first link you provided seems to indicate that they can be directly managed from android. So the question is to confirm whether it is only possible with the camera2 API or also is possible with the camera API

I have just ordered a CSI-2 camera, so soon I will have the whole kit (rPI3 + USB cam + CSI-2 cam) . But I'll have to wait since I'll be away (mini-vacations!!) next week. Will get back to it and try to find an answer if someone hasn't done it before.
 
Upvote 0

serro efe

Member
Licensed User
Longtime User
Thanks for the answer. I will continue to try the tests. If there is any improvement, I will report from here.
My camera is V1. Maybe a V2 camera is needed. So I ordered a V2 camera, and I will test it on a V2 camera.
https://developer.android.com/things/training/doorbell/camera-input.html
The picture on the link looks like the camera V2 picture.
https://www.raspberrypi.org/products/camera-module-v2/
https://www.pi-supply.com/product/raspberry-pi-camera-board-v1-3-5mp-1080p/

If you report the test results when the holiday is over, I'm happy.
Good holiday.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
V2 camera did not work. There must be a way.
@Erel, there is an idea. @JordiCP You have tested the camera
I don't understand what you try to build but if you want to connect a usb camera or the raspberry camera - it is simple to do it with B4J .
Of course it will require installing raspbian on your Pi.
For example, the code of a handler to send from a USB camera is:
B4X:
Public Sub Handle(req As ServletRequest, resp As ServletResponse)
    If Main.drive_flag = False Then
'        Log("picture taken  " & DateTime.time(DateTime.now))
        shl.Initialize("shl", "fswebcam", Array("-r","640x480","--no-banner", "temp.jpg"))
        shl.Run(-1)

        Dim img() As Byte
        img =  Bit.InputStreamToBytes(File.OpenInput(File.DirApp, "temp.jpg"))
        resp.Write(su.EncodeBase64(img))
    End If
End Sub

Please explain what you have and what you want and I'll try to help.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I have been playing today with a RPI-3 and a CSI-2 camera with Android Things. I must say that, up to now, I had never even plugged my RPI, so it was a nice surprise to see that it was quite straightforward to set the basics.

I tried to follow the same steps as you did with examples based on CameraEx and also JavaCameraView from the OpenCV library. Both of them crashed with log errors that I had never seen in Android devices...
I searched for these errors a bit and it "seems" that the hardware layer used (something named HAL3) isn't 100% compatible (at least at this moment) with the Android Camera API, and camera2 API must be used.

In short: in order to use a CSI-2 camera with the Raspberry Pi 3, you can either use Raspbian as suggested by @derez (or other systems that directly support it).
If you want to use Android Things, then you need to access it through the camera2 API. At this moment neither the B4A camera lib nor the OpenCV JavaCameraView are based on camera2 API.

The good news is that there is a Camera2Renderer class in OpenCV for Android that uses the camera2 API. The bad news is that I didn't wrap it in my library so it isn't available from B4A. Again the good news is that I will try to do it since I am also interested in it (but perhaps it will take some time)
 
Upvote 0

serro efe

Member
Licensed User
Longtime User
@JordiCP @derez thanks for the reply.
@derez I am writing a program with raspian, python, qt, no problem. I want to develop a product that works with android and kiosk (customer request).
@JordiCP You need the camera2 API to use piCamera. I have a little time for the project, I'll work a little with the camera2 API, I have never written a library before, how and where to start. If I can not get results, I can use ip camera. I will share it if there is improvement.
Thanks
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Do you need to combine it with the OpenCv library?
Perhaps an inline Java approach to set up the camera2 api, could work.
This approach would be more or less complex depending on your "real time" processing needs, or if you only need to get pictures from time to time.
I'll try to work on it with "normal" android and if I suceed will check if it also works with the rPI
 
Upvote 0

serro efe

Member
Licensed User
Longtime User
I do not need OpenCV in this project, I just have to take pictures when I want.
It looks like Android is running faster than raspian.
If so, Rpi3 + Picamera + Opencv + B4A GUI quartet can be used in many projects if it can work well.
Raspian for Qt, B4J or Lazarus is not bad as the interface, but the design process is long and desktop thought-out programs. Very fast application can be developed with B4A.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…