[Armadeus-commitlog] armadeus branch, master, updated. armadeus-6.0-435-g0dfeeb273
Brought to you by:
sszy
|
From: Julien B a. A. <ar...@us...> - 2018-07-04 14:24:34
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via 0dfeeb273a931adce05996a084fdffb729fb82c4 (commit)
from d951785c0d33b1880da966755ff7c2f6cf26b4d2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0dfeeb273a931adce05996a084fdffb729fb82c4
Author: Julien BOIBESSOT <jul...@ar...>
Date: Wed Jul 4 16:23:47 2018 +0200
[DEMOS] capture: add possibility to crop camera input and move cropping zone dynamically
-----------------------------------------------------------------------
Summary of changes:
target/demos/camera/capture/capture.c | 107 +++++++++++++++++++++++++++-------
1 file changed, 85 insertions(+), 22 deletions(-)
diff --git a/target/demos/camera/capture/capture.c b/target/demos/camera/capture/capture.c
index dd98045bb..db46a930e 100644
--- a/target/demos/camera/capture/capture.c
+++ b/target/demos/camera/capture/capture.c
@@ -84,8 +84,11 @@ struct camera mycamera;
unsigned int force_yuv420 = 0;
unsigned int force_fps = 0;
+unsigned int force_crop = 0;
unsigned int video_input = 0;
unsigned int capture_mode = 0;
+unsigned int crop_width = 0;
+unsigned int crop_height = 0;
#define FOURCC_TO_STR(fmt) fmt & 0xff, (fmt >> 8) & 0xff, (fmt >> 16) & 0xff, (fmt >> 24) & 0xff
@@ -605,6 +608,45 @@ static int read_frame(void)
return 1;
}
+static int do_cropping(unsigned int xoff, unsigned int yoff, unsigned int factor)
+{
+ struct v4l2_cropcap cropcap;
+ struct v4l2_crop crop;
+ struct v4l2_rect cropping;
+
+ CLEAR(cropcap);
+ cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ cropping.left = xoff;
+ cropping.top = yoff;
+ cropping.width = crop_width + factor;
+ cropping.height = crop_height + factor;
+
+ if (0 == xioctl(v4l_fd, VIDIOC_CROPCAP, &cropcap)) {
+ crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ if (!force_crop)
+ crop.c = cropcap.defrect; /* reset to default */
+ else
+ crop.c = cropping;
+
+ if (-1 == xioctl(v4l_fd, VIDIOC_S_CROP, &crop)) {
+ switch (errno) {
+ case EINVAL:
+ /* Cropping not supported. */
+ break;
+ default:
+ /* Errors ignored. */
+ break;
+ }
+ }
+ } else {
+ fprintf(stderr, "Camera (driver) doesn't support cropping\n");
+ /* Errors ignored. */
+ }
+
+ return 0;
+}
+
static int go_on = 1;
static int pause_capture = 0;
@@ -613,6 +655,9 @@ static void mainloop(void)
SDL_Event event;
struct stat exec_stat;
int ret;
+ static unsigned int xoff = 0;
+ static unsigned int yoff = 0;
+ static unsigned int factor = 0;
while (go_on) {
{
@@ -665,9 +710,35 @@ static void mainloop(void)
case SDLK_SPACE:
pause_capture = pause_capture ? 0 : 1;
break;
+ case SDLK_LEFT:
+ xoff -= 10;
+ break;
+ case SDLK_RIGHT:
+ xoff += 10;
+ break;
+ case SDLK_UP:
+ yoff -= 10;
+ break;
+ case SDLK_DOWN:
+ yoff += 10;
+ break;
+ case SDLK_PAGEUP:
+ factor += 64;
+ break;
+ case SDLK_PAGEDOWN:
+ factor -= 64;
+ break;
default:
break;
}
+ if (xoff >= 500)
+ xoff = 0;
+ if (yoff >= 500)
+ yoff = 0;
+ if (factor >= 500)
+ factor = 0;
+ do_cropping(xoff, yoff, factor);
+
break;
case SDL_QUIT:
@@ -1098,27 +1169,7 @@ static void init_capture_device(unsigned int capt_width, unsigned int capt_heigh
select_video_input();
- CLEAR(cropcap);
- cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
- if (0 == xioctl (v4l_fd, VIDIOC_CROPCAP, &cropcap)) {
- crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- crop.c = cropcap.defrect; /* reset to default */
-
- if (-1 == xioctl(v4l_fd, VIDIOC_S_CROP, &crop)) {
- switch (errno) {
- case EINVAL:
- /* Cropping not supported. */
- break;
- default:
- /* Errors ignored. */
- break;
- }
- }
- } else {
- /* Errors ignored. */
- }
-
+ do_cropping(0, 0, 0);
CLEAR(fmt);
fmt.fmt.pix.pixelformat = get_a_supported_pix_fmt();
@@ -1211,6 +1262,9 @@ static void usage(FILE *fp, int argc, char **argv)
fprintf (fp,
"Usage: %s [options]\n\n"
"Options:\n"
+ " -c | --crop WxH Crop camera input to WxH. In this mode, "
+ "offset can be changed with arrow keys "
+ "and window size with pageup/down (USB keyboard)\n"
" -d | --device name Video device name [/dev/video0]\n"
" -h | --help Print this message\n"
" -i | --input Use given video input (if many, 0 by default)\n"
@@ -1230,9 +1284,10 @@ static void usage(FILE *fp, int argc, char **argv)
argv[0], SCREEN_WIDTH, SCREEN_HEIGHT, CAM_WIDTH, CAM_HEIGHT);
}
-static const char short_options [] = "d:hi:mo:ruwtf:bxy";
+static const char short_options [] = "c:d:hi:mo:ruwtf:bxy";
static const struct option long_options [] = {
+ { "crop", required_argument, NULL, 'c' },
{ "verbose", no_argument, NULL, 'b' },
{ "device", required_argument, NULL, 'd' },
{ "fps", required_argument, NULL, 'f' },
@@ -1303,6 +1358,14 @@ int main(int argc, char **argv)
debug = 1;
break;
+ case 'c':
+ force_crop = 1;
+ sscanf(optarg, "%dx%d", &crop_width, &crop_height);
+ if (debug)
+ fprintf(stdout, "cropping to %dx%d\n",
+ crop_width, crop_height);
+ break;
+
case 'd':
dev_name = optarg;
break;
hooks/post-receive
--
armadeus
|