public class CameraPi
extends java.lang.Object
Through this wrapper, you can easily
We provide you with a set of predefined constructors to easily use all the available options.
Before using this, you need to enable camera support on your Raspberry Pi. This can be done by executing the following instructions on the command line.
First, download and install the latest kernel, GPU firmware and applications. You will need an internet connection for this to work correctly.
sudo apt-get update sudo apt-get upgrade
Now you need to enable camera support using the raspi-config.
sudo raspi-config
Use the cursor keys to move to the camera option and select "enable".
On exiting raspi-config it will ask to reboot. The enable option will ensure that on reboot the correct GPU firmware will be running (with the camera driver and tuning), and the GPU memory split is sufficient to allow the camera to acquire enough memory to run correctly.
Example of use: CameraPiExample
Modifier and Type | Method and Description |
---|---|
static int |
executeCommand(java.lang.String command)
Executes the specified string command in a separate process.
|
static void |
preview(int millis)
Enable a fullscreen preview for a duration of millis milliseconds.
|
static void |
preview(PreviewConfig previewConfig)
Enable a preview with specific config, for a default duration of 5000 milliseconds.
|
static void |
preview(PreviewConfig previewConfig,
int millis)
Enable a preview with specific preview configuration,
and for a duration of millis milliseconds.
|
static void |
startGStreamerServer(java.lang.String ipAddress,
int port,
int width,
int height,
boolean vflip,
boolean hflip,
int bitrate,
boolean preview,
boolean verbose)
Creates a new video stream from the Camera Pi, on a specific IP address:port,
using the GStreamer tool (v0.10).
|
static Picture |
takePicture()
Takes a picture as soon as possible, with default parameter values.
|
static Picture |
takePicture(int width,
int height,
int quality)
Takes a new picture with specified width, height and quality.
|
static Picture |
takePicture(PictureConfig config)
Takes a new picture with a custom PictureConfig.
|
static Picture |
takePicture(PictureConfig pictureConfig,
PreviewConfig previewConfig)
Takes a new picture with a custom PictureConfig,
and a PreviewConfig to enable a preview in the same time.
|
static Video |
takeVideo(int millis)
Takes a new video of millis milliseconds.
|
static Video |
takeVideo(int millis,
int width,
int height)
Takes a new video for duration of millis milliseconds, with specified width and height.
|
static Video |
takeVideo(VideoConfig config)
Takes a new video with the specified VideoConfig.
|
static Video |
takeVideo(VideoConfig videoConfig,
PreviewConfig previewConfig)
Takes a new video with the specific VideoConfig and a PreviewConfig to enable a preview in the same time.
|
public static int executeCommand(java.lang.String command)
command
- the string command to execute.public static void preview(int millis)
The preview can only be done with an HDMI display (directly connected to the Pi), or a display connected through the PCB display port (we couldn't test this). A vnc connection is not sufficient.
millis
- the duration of the preview, in milliseconds.public static void preview(PreviewConfig previewConfig)
previewConfig
- the preview configuration to apply on the image.public static void preview(PreviewConfig previewConfig, int millis)
previewConfig
- the preview configuration to apply on the image.millis
- the duration of the preview, in milliseconds.public static Picture takePicture()
No preview.
public static Picture takePicture(int width, int height, int quality)
No preview.
width
- the width of the new picture, in the [PictureConfig.MIN_WIDTH
, PictureConfig.MAX_WIDTH
] range.height
- the height of the new picture, in the [PictureConfig.MIN_HEIGHT
, PictureConfig.MAX_HEIGHT
] range.quality
- the quality of the new picture, in the [PictureConfig.MIN_QUALITY
, PictureConfig.MAX_QUALITY
] range.public static Picture takePicture(PictureConfig config)
No preview.
config
- the PictureConfig to apply to take the picture.public static Picture takePicture(PictureConfig pictureConfig, PreviewConfig previewConfig)
pictureConfig
- the PictureConfig to apply to take the picture.previewConfig
- the PreviewConfig to apply to take the picture.public static Video takeVideo(int millis)
No preview.
millis
- the duration of the video, in milliseconds.public static Video takeVideo(int millis, int width, int height)
No preview.
millis
- the duration of the video, in milliseconds.width
- the width of the new video.height
- rge height of the new video.public static Video takeVideo(VideoConfig config)
No preview.
config
- the VideoConfig to apply to take the video.public static Video takeVideo(VideoConfig videoConfig, PreviewConfig previewConfig)
videoConfig
- the VideoConfig to apply to take the video.previewConfig
- the PreviewConfig to apply to take the video.public static void startGStreamerServer(java.lang.String ipAddress, int port, int width, int height, boolean vflip, boolean hflip, int bitrate, boolean preview, boolean verbose)
There is no need to stop this GStreamer server. It will shut down when the java process will end.
ipAddress
- the IP address linked to the video stream.port
- the port linked to the video stream.width
- the width of the video stream. Higher is better, but requires larger network load.height
- the height of the video stream. Higher is better, but requires larger network load.vflip
- true to flip the image vertically. False otherwise.hflip
- true to flip the image horizontally. False otherwise.bitrate
- the bitrate used for the video stream.preview
- true to enable a fullscreen preview.verbose
- true to print gstreamer through Tools.log system.