caprica / picam

Unofficial Java API library for the Raspberry Pi camera.
GNU General Public License v3.0
49 stars 11 forks source link

Encoding RGB24, BGR24 with error in MMAL #23

Closed miguelrvs closed 4 years ago

miguelrvs commented 4 years ago

Hi,

I have a copy of uk.co.caprica.picam.app.Snap for testing. I was testing so changed the encoding from JPEG to RGB24 and it fails with the following error:

Encoding: RGB24
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x7508c2a0 (EINVAL)
Exception in thread "main" uk.co.caprica.picam.CameraException: Failed to open camera

Removed the quality param, but did not make any diference, also width and height; all to no avail. Then tested all of the encodings: Work: JPEG, PNG, GIF Don't work: RGB24, BGR24, I420, OPAQUE The hex after mmal_vc_port_info_set is different every time.


Temporarily installed picam native library to /tmp/picam-2.0.1.so

def Encoding: PNG
def timeout: 0
Encoding: BGR24
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x750b7280 (EINVAL)
Exception in thread "main" uk.co.caprica.picam.CameraException: Failed to open camera
    at uk.co.caprica.picam.Camera.<init>(Camera.java:92)
    at mx.com.fcm.pirexicam.picam.PicamMain2.main(PicamMain2.java:57)
pi@raspberrypi:/media/pi/82AE-88F9/pi $ java  -cp pirexicam-picam-0.0.1-SNAPSHOT.jar -Dencoding=RGB24  mx.com.fcm.pirexicam.picam.PicamMain2 foto.jpg
Temporarily installed picam native library to /tmp/picam-2.0.1.so

def Encoding: PNG
def timeout: 0
Encoding: RGB24
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x7508c2a0 (EINVAL)
Exception in thread "main" uk.co.caprica.picam.CameraException: Failed to open camera
    at uk.co.caprica.picam.Camera.<init>(Camera.java:92)
    at mx.com.fcm.pirexicam.picam.PicamMain2.main(PicamMain2.java:57)
pi@raspberrypi:/media/pi/82AE-88F9/pi $ 
:
def Encoding: PNG
def timeout: 0
Encoding: OPAQUE
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x74fa6290 (EINVAL)
Exception in thread "main" uk.co.caprica.picam.CameraException: Failed to open camera
    at uk.co.caprica.picam.Camera.<init>(Camera.java:92)
    at mx.com.fcm.pirexicam.picam.PicamMain2.main(PicamMain2.java:57)
pi@raspberrypi:/media/pi/82AE-88F9/pi $ java  -cp pirexicam-picam-0.0.1-SNAPSHOT.jar -Dencoding=I420  mx.com.fcm.pirexicam.picam.PicamMain2 foto.jpg
Temporarily installed picam native library to /tmp/picam-2.0.1.so

def Encoding: PNG
def timeout: 0
Encoding: I420
mmal: mmal_vc_port_info_set: failed to set port info (3:0): EINVAL
mmal: mmal_vc_port_set_format: mmal_vc_port_info_set failed 0x74fa5270 (EINVAL)
Exception in thread "main" uk.co.caprica.picam.CameraException: Failed to open camera
    at uk.co.caprica.picam.Camera.<init>(Camera.java:92)
    at mx.com.fcm.pirexicam.picam.PicamMain2.main(PicamMain2.java:57)

I need to process the image and show live on screen so a JPEG conversion is unnecessary, would be better BGR or RGB than any compressed format.

Does anyone has a similar problem?

(this is the code, for everyone reference) PicamMain2.txt

caprica commented 4 years ago

But "RGB24" is not an encoding is it, it's a chroma format. PNG is an encoding, or JPG.

caprica commented 4 years ago

It's been a while since I worked on this project, but if I remember correctly, the chroma format has to be delicately set up between the native resources - camera, the encoder and so on. There's not an easy way to change that, and I'm not sure why you need to change it anyway.

miguelrvs commented 4 years ago

Well, I put RGB24 because it is a member of enum uk.co.caprica.picam.enums.Encoding; so it is a valid value in CameraConfiguration.encoding(Encoding) . I thought I would be obtaining the raw pixels. I need to display the image in real-time, so the uncompressed (and unprocecessed) pixels are the most efficient way of doing it. Maybe the BMP is the easiest way of having the pixels.

caprica commented 4 years ago

That's a fair comment and it looks like I might have been wrong to include those on that enum. The fact is that the native code is rejecting those values as invalid.

miguelrvs commented 4 years ago

Knowing that, I'm already doing with BMP; Might dive later into MMAL to make a better use the camera and the rasberry pi resources Thank you