caprica / picam

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

How to reduce picture size #18

Closed AlexanderBykin closed 4 years ago

AlexanderBykin commented 4 years ago

Hi I am looking for solution to reduce taken picture size. As an example:

Any suggestions to reduce size?

AlexanderBykin commented 4 years ago

here is the original raspimjeg config there i see some mmal settings

caprica commented 4 years ago

Doesn't picam already expose a jpeg quality setting that you can use? The default is 85 IIRC, but it's been a while since I've used this.

caprica commented 4 years ago

The README gives this example:

CameraConfiguration config = cameraConfiguration()
    .width(1920)
    .height(1080)
    .encoding(Encoding.JPEG)
    .quality(85);

So try playing around with values for quality:

CameraConfiguration config = cameraConfiguration()
    .width(1920)
    .height(1080)
    .encoding(Encoding.JPEG)
    .quality(50);
caprica commented 4 years ago

Oh I see I may not have read your original issue carefully enough, you already tried quality settings.

I don't know then.

AlexanderBykin commented 4 years ago

is it possible to have an output image in the RGB565 format ? i think this will reduce a lot of size.

caprica commented 4 years ago

Maybe. If it's not too much different from PNG or JPG it should be easy. I'll try and have a look but it won't be until the weekend.

AlexanderBykin commented 4 years ago

just a bump on the thread cool things happens here 660 fps on the RPi camera A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera

caprica commented 4 years ago

That thread is from May 2015 I think. Anyway, I'm not sure, this particular library is supposed to make it trivial for people to capture JPG/PNG etc using Java. That's the scope of it and not much more. It might be easy enough to capture RAW, I don't know yet, but capturing video is definitely not in scope. For capturing video I would always first try VLC/LibVLC/vlcj.

caprica commented 4 years ago

So RGB565 is a colour format, not a container format, how are you suggesting to get an RGB565 image out of the Pi?

These are the defined container formats:

define MMAL_ENCODING_JPEG MMAL_FOURCC('J','P','E','G')

define MMAL_ENCODING_GIF MMAL_FOURCC('G','I','F',' ')

define MMAL_ENCODING_PNG MMAL_FOURCC('P','N','G',' ')

define MMAL_ENCODING_PPM MMAL_FOURCC('P','P','M',' ')

define MMAL_ENCODING_TGA MMAL_FOURCC('T','G','A',' ')

define MMAL_ENCODING_BMP MMAL_FOURCC('B','M','P',' ')

It's not clear to me what specifically needs to be done.

AlexanderBykin commented 4 years ago

i think JPEG will be nice in terms of size in bytes and image quality

caprica commented 4 years ago

But it generates JPG already, with a quality setting. I thought you were asking me to set RGB565 colour format, but it's not at all clear to me how to do that with the MMAL API.

AlexanderBykin commented 4 years ago

yes i know about JPEG. please look at here there is MMAL_ENCODING_RGB16 that is equals to RGB565 we just need to find implementation of this in C source code

caprica commented 4 years ago

The only place I saw those particular encodings used was for the video decoder colour formats, not static images.

jpg is 24-bit, png is 8, 24 or 32 bit.

Unless you can find some example that shows how to use MMAL to write out an image in RGB565 format, then I just don't know...

AlexanderBykin commented 4 years ago

hi, it looks like RGB565 is not possible for JPG format see here but anyway i don't understand why your library takes more bytes size then RaspiMJPEG for taken image

caprica commented 4 years ago

For jpg, the code simply sets the encoder up with the format and sets the quality factor. As you probably know by now, the code was basically ported from the "C" version.

So if you pass the same quality setting and the same picture size as you use with that native command-line tool, the results should be comparable.

I will have a quick review of the code and see if there's an obvious bug.

caprica commented 4 years ago

I had a quick scan of the code, I don't see anything wrong - it looks to me like the quality should definitely be set when using jpg.

When I test it I do see a notable difference with what I believe to be broadly similar settings in Raspistill and using the picam library.

I do 800x600 jpg at q=85.

I use a 3 second capture delay in my library - less detail is captured and therefore smaller file size if your capture delay is too short.

I see variation in the difference if I run multiple times or take multiple different shots.

In the last test I did:

Raspistill gives a 305k file. Picam gives a 350k file.

The pictures are the same scene, same illumination etc. Nothing moving in the frame so the pictures are pretty much identical.

It is clear from the pictures that there is some slight difference in the output, not much, but some.

Output of the "file" command:

picam.jpg:  JPEG image data, Exif standard: [TIFF image data, big-endian, direntries=9, height=0, model=ov5647, xresolution=130, yresolution=138, resolutionunit=2, datetime=1970:01:01 00:00:00, width=0], baseline, precision 8, 800x600, frames 3

And:

native.jpg: JPEG image data, Exif standard: [TIFF image data, big-endian, direntries=10, height=0, manufacturer=RaspberryPi, model=RP_ov5647, xresolution=156, yresolution=164, resolutionunit=2, datetime=2019:11:04 19:25:22, width=0], baseline, precision 8, 800x600, frames 3

Only thing that jumps out different there are the resolution values.

picam picam

native native

So... upshot... I dunno.

caprica commented 4 years ago

Switching to PNG encoding also shows a difference, so the most likely explanation is that there is something different in the defaults when using Raspistill vs using Picam.