3
3
* Copyright (c) 2002 Philip Gladstone
5
* This file implements a fish detector. It is used to see when a
5
* This file implements a fish detector. It is used to see when a
6
6
* goldfish passes in front of the camera. It does this by counting
7
7
* the number of input pixels that fall within a particular HSV
19
19
* -d turn debugging on
20
20
* -D <directory> where to put the fish images
22
* This library is free software; you can redistribute it and/or
22
* This file is part of FFmpeg.
24
* FFmpeg is free software; you can redistribute it and/or
23
25
* modify it under the terms of the GNU Lesser General Public
24
26
* License as published by the Free Software Foundation; either
25
* version 2 of the License, or (at your option) any later version.
27
* version 2.1 of the License, or (at your option) any later version.
27
* This library is distributed in the hope that it will be useful,
29
* FFmpeg is distributed in the hope that it will be useful,
28
30
* but WITHOUT ANY WARRANTY; without even the implied warranty of
29
31
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30
32
* Lesser General Public License for more details.
32
34
* You should have received a copy of the GNU Lesser General Public
33
* License along with this library; if not, write to the Free Software
34
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35
* License along with FFmpeg; if not, write to the Free Software
36
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36
38
#include <stdlib.h>
208
220
hsv->h = i + (60 * f) / (v - x);
212
224
hsv->s = (255 * (v - x)) / v;
218
230
void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
220
232
ContextInfo *ci = (ContextInfo *) ctx;
221
uint8_t *cm = cropTbl + MAX_NEG_CROP;
233
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
222
234
int rowsize = picture->linesize[0];
269
281
get_hsv(&hsv, r, g, b);
272
284
fprintf(stderr, "(%d,%d,%d) -> (%d,%d,%d)\n",
273
285
r,g,b,hsv.h,hsv.s,hsv.v);
276
288
if (hsv.h >= ci->dark.h && hsv.h <= ci->bright.h &&
277
289
hsv.s >= ci->dark.s && hsv.s <= ci->bright.s &&
278
hsv.v >= ci->dark.v && hsv.v <= ci->bright.v) {
290
hsv.v >= ci->dark.v && hsv.v <= ci->bright.v) {
280
292
} else if (ci->zapping) {
281
293
y[0] = y[1] = y[rowsize] = y[rowsize + 1] = 16;
328
340
if (foundfile < ci->file_limit) {
329
344
size = avpicture_get_size(PIX_FMT_RGB24, width, height);
330
345
buf = av_malloc(size);
332
347
avpicture_fill(&picture1, buf, PIX_FMT_RGB24, width, height);
333
if (img_convert(&picture1, PIX_FMT_RGB24,
334
picture, pix_fmt, width, height) >= 0) {
349
// if we already got a SWS context, let's realloc if is not re-useable
350
ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx,
351
width, height, pix_fmt,
352
width, height, PIX_FMT_RGB24,
353
sws_flags, NULL, NULL, NULL);
354
if (ci->toRGB_convert_ctx == NULL) {
355
av_log(NULL, AV_LOG_ERROR,
356
"Cannot initialize the toRGB conversion context\n");
359
// img_convert parameters are 2 first destination, then 4 source
360
// sws_scale parameters are context, 4 first source, then 2 destination
361
sws_scale(ci->toRGB_convert_ctx,
362
picture->data, picture->linesize, 0, height,
363
picture1.data, picture1.linesize);
335
365
/* Write out the PPM file */
340
sprintf(fname, "%s/fishimg%ld_%lld.ppm", ci->dir, time(0), pts);
366
snprintf(fname, sizeof(fname), "%s/fishimg%ld_%"PRId64".ppm", ci->dir, (long)(av_gettime() / 1000000), pts);
341
367
f = fopen(fname, "w");
343
369
fprintf(f, "P6 %d %d 255\n", width, height);
344
370
fwrite(buf, width * height * 3, 1, f);
350
ci->next_pts = pts + ci->min_interval;
375
ci->next_pts = pts + ci->min_interval;