Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Try to capture from arducam on RPI as fast as possible.
#include "arducam_mipicamera.h"
#include <linux/v4l2-controls.h>
#include <stdio.h>
#include <sys/time.h>
void capture_image(CAMERA_INSTANCE camera_instance) {
IMAGE_FORMAT fmt = {IMAGE_ENCODING_RAW_BAYER, 0};
BUFFER *buffer = arducam_capture(camera_instance, &fmt, 6000);
arducam_release_buffer(buffer);
}
unsigned long long millis() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (unsigned long long)(tv.tv_sec) * 1000 +
(unsigned long long)(tv.tv_usec) / 1000;
}
int main(int argc, char **argv) {
CAMERA_INSTANCE camera_instance;
int width = 4656, height = 3496;
unsigned int n = 20;
arducam_init_camera(&camera_instance);
arducam_set_resolution(camera_instance, &width, &height);
arducam_software_auto_exposure(camera_instance, 0);
arducam_software_auto_white_balance(camera_instance, 1);
arducam_set_control(camera_instance, V4L2_CID_EXPOSURE, 200);
arducam_set_control(camera_instance, V4L2_CID_FOCUS_ABSOLUTE, 100);
arducam_write_sensor_reg(camera_instance, 0x0307, 74);
// first image capture is slow
capture_image(camera_instance);
unsigned long long start = millis();
for (int i = 0; i < n; i++) {
capture_image(camera_instance);
}
unsigned long long end = millis();
float duration = end - start;
printf("average duration: %f ms\n", duration / n);
printf("average framerate: %f fps\n", 1000 * n / duration);
arducam_close_camera(camera_instance);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment