caprica / picam

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

Low Brightness problem #26

Closed ElectroBoy404NotFound closed 2 years ago

ElectroBoy404NotFound commented 2 years ago

Hello! Im using the version 2 of picam and JFrame to show the picture, but the brightness is quite low. Picture: 2021-09-25-131719_1024x768_scrot Picture using other software: 2021-09-25-132129_1024x768_scrot My Code:

package testt;

import static uk.co.caprica.picam.PicamNativeLibrary.installTempLibrary;

import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import uk.co.caprica.picam.Camera;
import uk.co.caprica.picam.CameraConfiguration;
import uk.co.caprica.picam.NativeLibraryException;
import uk.co.caprica.picam.PictureCaptureHandler;
import uk.co.caprica.picam.enums.Encoding;

public class t {

    public static JFrame gui = new JFrame("Camera");
    public static JLabel imgFrame = new JLabel();

    public static void main(String[] args) {
        gui.setSize(new Dimension(640, 480));
        gui.setLocationRelativeTo(null);
        gui.setVisible(true);
        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        imgFrame.setBounds(0, 0, 640, 480);
        imgFrame.setVisible(true);
        gui.add(imgFrame);

        try {
            installTempLibrary();
        } catch (NativeLibraryException e1) {
            e1.printStackTrace();
        }
        try (Camera camera = new Camera(CameraConfiguration.cameraConfiguration().width(640).height(480).encoding(Encoding.JPEG).quality(100))) {
            while(true) camera.takePicture(new PictureCaptureHandler<BufferedImage>() {
                private BufferedImage img;
                private List<Byte> data = new ArrayList<Byte>();

                public void begin() throws Exception {
                    data.clear();
                }
                public int pictureData(byte[] data) throws Exception {
                    for(byte b : data) this.data.add(b);
                    return data.length;
                }
                public void end() throws Exception {
                    byte[] bytes = new byte[data.size()];
                    int i = 0;
                    for(byte b : data) { bytes[i] = b; i++; }
                    t.imgFrame.setIcon((new ImageIcon(bytes)));
                }
                public BufferedImage result() {
                    return img;
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Sorry if im doing anything wrong, im new actually.

caprica commented 2 years ago

Probably you need to use a longer exposure time, or a longer delay while the sensor "settles" before taking the picture.

The other software you're using is just using different camera configuration, the camera configuration is there for you to experiment with, don't just assume the default configuration is right for your needs.

ElectroBoy404NotFound commented 2 years ago

oh ok, can i like get an example? and sorry, i was away

caprica commented 2 years ago

There is nothing other than what is already provided here. Experiment with the available configuration settings and the camera API.