28 #include <opencv/cv.h>
29 #include <opencv/cxcore.h>
37 int depth, channels_nb;
39 if (pixfmt ==
PIX_FMT_GRAY8) { depth = IPL_DEPTH_8U; channels_nb = 1; }
40 else if (pixfmt ==
PIX_FMT_BGRA) { depth = IPL_DEPTH_8U; channels_nb = 4; }
41 else if (pixfmt ==
PIX_FMT_BGR24) { depth = IPL_DEPTH_8U; channels_nb = 3; }
44 tmpimg = cvCreateImageHeader((CvSize){picref->
video->
w, picref->
video->
h},
depth, channels_nb);
46 img->imageData = img->imageDataOrigin = picref->
data[0];
47 img->dataOrder = IPL_DATA_ORDER_PIXEL;
48 img->origin = IPL_ORIGIN_TL;
49 img->widthStep = picref->
linesize[0];
54 picref->
linesize[0] = img->widthStep;
55 picref->
data[0] = img->imageData;
88 char type_str[128] =
"gaussian";
96 sscanf(args,
"%127[^:]:%d:%d:%lf:%lf", type_str, &smooth->
param1, &smooth->
param2, &smooth->
param3, &smooth->
param4);
98 if (!strcmp(type_str,
"blur" )) smooth->
type = CV_BLUR;
99 else if (!strcmp(type_str,
"blur_no_scale")) smooth->
type = CV_BLUR_NO_SCALE;
100 else if (!strcmp(type_str,
"median" )) smooth->
type = CV_MEDIAN;
101 else if (!strcmp(type_str,
"gaussian" )) smooth->
type = CV_GAUSSIAN;
102 else if (!strcmp(type_str,
"bilateral" )) smooth->
type = CV_BILATERAL;
110 "Invalid value '%d' for param1, it has to be a positive odd number\n",
114 if ((smooth->
type == CV_BLUR || smooth->
type == CV_BLUR_NO_SCALE || smooth->
type == CV_GAUSSIAN) &&
117 "Invalid value '%d' for param2, it has to be zero or a positive odd number\n",
137 uint8_t *buf, *p, *pend;
141 if ((ret =
av_file_map(filename, &buf, &size, 0, log_ctx)) < 0)
146 for (i = 0; i <
size; i++) {
147 if (buf[i] ==
'\n') {
148 if (*rows == INT_MAX) {
153 *cols =
FFMAX(*cols, w);
155 }
else if (w == INT_MAX) {
161 if (*rows > (SIZE_MAX /
sizeof(
int) / *cols)) {
166 if (!(*values =
av_mallocz(
sizeof(
int) * *rows * *cols)))
172 for (i = 0; i < *rows; i++) {
174 if (p > pend || *p ==
'\n') {
178 (*values)[*cols*i + j] = !!isgraph(*(p++));
188 for (i = 0; i < *rows; i++) {
189 for (j = 0; j < *cols; j++)
190 line[j] = (*values)[i * *cols + j] ?
'@' :
' ';
203 char shape_filename[128] =
"", shape_str[32] =
"rect";
204 int cols = 0, rows = 0, anchor_x = 0, anchor_y = 0, shape = CV_SHAPE_RECT;
205 int *values =
NULL, ret;
207 sscanf(buf,
"%dx%d+%dx%d/%32[^=]=%127s", &cols, &rows, &anchor_x, &anchor_y, shape_str, shape_filename);
209 if (!strcmp(shape_str,
"rect" )) shape = CV_SHAPE_RECT;
210 else if (!strcmp(shape_str,
"cross" )) shape = CV_SHAPE_CROSS;
211 else if (!strcmp(shape_str,
"ellipse")) shape = CV_SHAPE_ELLIPSE;
212 else if (!strcmp(shape_str,
"custom" )) {
213 shape = CV_SHAPE_CUSTOM;
218 "Shape unspecified or type '%s' unknown\n.", shape_str);
222 if (rows <= 0 || cols <= 0) {
224 "Invalid non-positive values for shape size %dx%d\n", cols, rows);
228 if (anchor_x < 0 || anchor_y < 0 || anchor_x >= cols || anchor_y >= rows) {
230 "Shape anchor %dx%d is not inside the rectangle with size %dx%d.\n",
231 anchor_x, anchor_y, cols, rows);
235 *kernel = cvCreateStructuringElementEx(cols, rows, anchor_x, anchor_y, shape, values);
240 av_log(log_ctx,
AV_LOG_INFO,
"Structuring element: w:%d h:%d x:%d y:%d shape:%s\n",
241 rows, cols, anchor_x, anchor_y, shape_str);
254 char default_kernel_str[] =
"3x3+0x0/rect";
256 const char *buf = args;
264 *kernel_str ? kernel_str : default_kernel_str,
284 cvReleaseStructuringElement(&dilate->
kernel);
318 char name[128], priv_args[1024];
322 sscanf(args,
"%127[^=:]%c%1023s", name, &c, priv_args);
326 if (!strcmp(name, entry->
name)) {
334 return ocv->
init(ctx, priv_args, opaque);
349 memset(ocv, 0,
sizeof(*ocv));
359 IplImage inimg, outimg;
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx)
AVFilterBufferRefVideoProps * video
video buffer specific properties
int linesize[8]
number of bytes per line
static OCVFilterEntry ocv_filter_entries[]
int h
agreed upon image height
AVFilterBufferRef * out_buf
#define FF_ARRAY_ELEMS(a)
void(* uninit)(AVFilterContext *ctx)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define AV_PERM_READ
can read from the buffer
static void smooth_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
static av_cold void dilate_uninit(AVFilterContext *ctx)
void(* end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
void avfilter_end_frame(AVFilterLink *link)
Notifie the next filter that the current frame has finished.
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
A filter pad used for either input or output.
A link between two filters.
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
int(* init)(AVFilterContext *ctx, const char *args, void *opaque)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
void av_log(void *avcl, int level, const char *fmt,...)
AVFilterFormats * avfilter_make_format_list(const int *fmts)
Create a list of supported formats.
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
static void dilate_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
static void fill_picref_from_iplimage(AVFilterBufferRef *picref, const IplImage *img, enum PixelFormat pixfmt)
static av_cold int dilate_init(AVFilterContext *ctx, const char *args, void *opaque)
void(* end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
void(* uninit)(AVFilterContext *ctx)
int(* init)(AVFilterContext *ctx, const char *args, void *opaque)
void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
Send a slice to the next filter.
int format
agreed upon media format
void avfilter_unref_buffer(AVFilterBufferRef *ref)
Remove a reference to a buffer.
A reference to an AVFilterBuffer.
static void end_frame(AVFilterLink *inlink)
static av_cold int smooth_init(AVFilterContext *ctx, const char *args, void *opaque)
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold void uninit(AVFilterContext *ctx)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
const char * name
filter name
static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename, void *log_ctx)
packed RGB 8:8:8, 24bpp, BGRBGR...
AVFilterLink ** outputs
array of pointers to output links
static void fill_iplimage_from_picref(IplImage *img, const AVFilterBufferRef *picref, enum PixelFormat pixfmt)
static void erode_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int query_formats(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
AVFilterContext * dst
dest filter
uint8_t * data[8]
picture/audio data for each plane
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
AVFilterBufferRef * cur_buf