Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
video_capture.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015
3 *
4 * This file is part of Paparazzi.
5 *
6 * Paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * Paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
26#include <stdio.h>
27#include <unistd.h>
28#include <stdlib.h>
29#include <time.h>
30
33
34#include "lib/encoding/jpeg.h"
35
36// Note: this define is set automatically when the video_exif module is included,
37// and exposes functions to write data in the image exif headers.
38#if JPEG_WITH_EXIF_HEADER
40#endif
41
42#ifndef VIDEO_CAPTURE_PATH
43#define VIDEO_CAPTURE_PATH /data/video/images
44#endif
45
46#ifndef VIDEO_CAPTURE_JPEG_QUALITY
47#define VIDEO_CAPTURE_JPEG_QUALITY 99
48#endif
49
50#ifndef VIDEO_CAPTURE_FPS
51#define VIDEO_CAPTURE_FPS 0
52#endif
54
55// Module settings
56bool video_capture_take_shot = false; // Capture single images
57bool video_capture_record_video = false; // Capture video
59
60// Save directory
61static char save_dir[256];
62
63// Forward function declarations
64struct image_t *video_capture_func(struct image_t *img, uint8_t camera_id);
65void video_capture_save(struct image_t *img);
66
67
69{
70 // Create images directory with timestamp
71 struct timeval tv;
72 struct tm *tm;
74 tm = localtime(&tv.tv_sec);
75
76 sprintf(save_dir, "%s/%04d%02d%02d-%02d%02d%02d", STRINGIFY(VIDEO_CAPTURE_PATH),
77 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
78 tm->tm_hour, tm->tm_min, tm->tm_sec);
79 // Folder creation delayed until capture starts, see video_capture_save.
80 // This prevents empty folders if nothing is actually recorded.
81
82 // Add function to computer vision pipeline
84}
85
86
87struct image_t *video_capture_func(struct image_t *img, uint8_t camera_id __attribute__((unused)))
88{
89 // If take_shot bool is set, save the image
93 }
94
95 // No modification to image
96 return NULL;
97}
98
99
101{
102 // Set take_shot bool to true
104}
105
109
113
115{
116 // Create output folder if necessary
117 if (access(save_dir, F_OK)) {
118 char save_dir_cmd[266]; // write 10b + [0:256]
119 sprintf(save_dir_cmd, "mkdir -p %s", save_dir);
120 if (system(save_dir_cmd) != 0) {
121 printf("[video_capture] Could not create images directory %s.\n", save_dir);
122 return;
123 }
124 }
125
126 // Declare storage for image location
127 char save_name[266]; // write 10b + [0-256]
128
129 // Generate image filename from image timestamp
130 sprintf(save_name, "%s/%u.jpg", save_dir, img->pprz_ts);
131 printf("[video_capture] Saving image to %s.\n", save_name);
132
133 // Create jpg image from raw frame
134 struct image_t img_jpeg;
137
138#if JPEG_WITH_EXIF_HEADER
140#else
141 // Open file
142 FILE *fp = fopen(save_name, "w");
143 if (fp == NULL) {
144 printf("[video_capture] Could not write shot %s.\n", save_name);
145 return;
146 }
147
148 // Save it to the file and close it
149 fwrite(img_jpeg.buf, sizeof(uint8_t), img_jpeg.buf_size, fp);
150 fclose(fp);
151#endif
152
153 // Free image
155}
struct video_listener * cv_add_to_device(struct video_config_t *device, cv_function func, uint16_t fps, uint8_t id)
Definition cv.c:46
Computer vision framework for onboard processing.
int write_exif_jpeg(char *filename, const unsigned char *image_jpg, const unsigned int image_jpg_len, const unsigned int image_jpg_x, const unsigned int image_jpg_y)
Write JPEG images containing EXIF headers with GPS coordinates.
void image_free(struct image_t *img)
Free the image.
Definition image.c:75
void image_create(struct image_t *img, uint16_t width, uint16_t height, enum image_type type)
Create a new image.
Definition image.c:43
@ IMAGE_JPEG
An JPEG encoded image (not per pixel encoded)
Definition image.h:38
void jpeg_encode_image(struct image_t *in, struct image_t *out, uint32_t quality_factor, bool add_dri_header)
Encode an YUV422 image.
Definition jpeg.c:408
Encode images with the use of the JPEG encoding.
uint16_t foo
Definition main_demo5.c:58
#define false
Definition microrl.h:7
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
static char save_dir[256]
bool video_capture_record_video
bool video_capture_take_shot
#define VIDEO_CAPTURE_JPEG_QUALITY
#define VIDEO_CAPTURE_PATH
struct image_t * video_capture_func(struct image_t *img, uint8_t camera_id)
#define VIDEO_CAPTURE_FPS
Default FPS (zero means run at camera fps)
void video_capture_save(struct image_t *img)
void video_capture_start_capture(void)
int video_capture_index
void video_capture_stop_capture(void)
void video_capture_shoot(void)
void video_capture_init(void)
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.