Go to the documentation of this file.
27 #if HAVE_OPENCV2_CORE_CORE_C_H
28 #include <opencv2/core/core_c.h>
29 #include <opencv2/imgproc/imgproc_c.h>
31 #include <opencv/cv.h>
32 #include <opencv/cxcore.h>
46 int depth, channels_nb;
53 tmpimg = cvCreateImageHeader((CvSize){
frame->width,
frame->height}, depth, channels_nb);
55 img->imageData =
img->imageDataOrigin =
frame->data[0];
56 img->dataOrder = IPL_DATA_ORDER_PIXEL;
57 img->origin = IPL_ORIGIN_TL;
87 char type_str[128] =
"gaussian";
95 sscanf(args,
"%127[^|]|%d|%d|%lf|%lf", type_str, &
smooth->param1, &
smooth->param2, &
smooth->param3, &
smooth->param4);
97 if (!strcmp(type_str,
"blur" ))
smooth->type = CV_BLUR;
98 else if (!strcmp(type_str,
"blur_no_scale"))
smooth->type = CV_BLUR_NO_SCALE;
99 else if (!strcmp(type_str,
"median" ))
smooth->type = CV_MEDIAN;
100 else if (!strcmp(type_str,
"gaussian" ))
smooth->type = CV_GAUSSIAN;
101 else if (!strcmp(type_str,
"bilateral" ))
smooth->type = CV_BILATERAL;
109 "Invalid value '%d' for param1, it has to be a positive odd number\n",
113 if ((
smooth->type == CV_BLUR ||
smooth->type == CV_BLUR_NO_SCALE ||
smooth->type == CV_GAUSSIAN) &&
116 "Invalid value '%d' for param2, it has to be zero or a positive odd number\n",
136 uint8_t *buf, *p, *pend;
146 if (buf[
i] ==
'\n') {
147 if (*rows == INT_MAX) {
155 }
else if (
w == INT_MAX) {
161 if (*rows > (SIZE_MAX /
sizeof(
int) / *cols)) {
175 for (
i = 0;
i < *rows;
i++) {
177 if (p > pend || *p ==
'\n') {
193 for (
i = 0;
i < *rows;
i++) {
194 for (j = 0; j < *cols; j++)
208 char shape_filename[128] =
"", shape_str[32] =
"rect";
209 int cols = 0, rows = 0, anchor_x = 0, anchor_y = 0, shape = CV_SHAPE_RECT;
212 sscanf(buf,
"%dx%d+%dx%d/%32[^=]=%127s", &cols, &rows, &anchor_x, &anchor_y, shape_str, shape_filename);
214 if (!strcmp(shape_str,
"rect" )) shape = CV_SHAPE_RECT;
215 else if (!strcmp(shape_str,
"cross" )) shape = CV_SHAPE_CROSS;
216 else if (!strcmp(shape_str,
"ellipse")) shape = CV_SHAPE_ELLIPSE;
217 else if (!strcmp(shape_str,
"custom" )) {
218 shape = CV_SHAPE_CUSTOM;
223 "Shape unspecified or type '%s' unknown.\n", shape_str);
228 if (rows <= 0 || cols <= 0) {
230 "Invalid non-positive values for shape size %dx%d\n", cols, rows);
235 if (anchor_x < 0 || anchor_y < 0 || anchor_x >= cols || anchor_y >= rows) {
237 "Shape anchor %dx%d is not inside the rectangle with size %dx%d.\n",
238 anchor_x, anchor_y, cols, rows);
243 *kernel = cvCreateStructuringElementEx(cols, rows, anchor_x, anchor_y, shape,
values);
250 rows, cols, anchor_x, anchor_y, shape_str);
265 char default_kernel_str[] =
"3x3+0x0/rect";
266 char *kernel_str =
NULL;
267 const char *buf = args;
278 (!kernel_str || !*kernel_str) ? default_kernel_str
285 if (!buf || sscanf(buf,
"|%d", &
dilate->nb_iterations) != 1)
286 dilate->nb_iterations = 1;
288 if (
dilate->nb_iterations <= 0) {
301 cvReleaseStructuringElement(&
dilate->kernel);
308 cvDilate(inimg, outimg,
dilate->kernel,
dilate->nb_iterations);
315 cvErode(inimg, outimg,
dilate->kernel,
dilate->nb_iterations);
343 if (!strcmp(
s->name, entry->
name)) {
344 s->init = entry->
init;
350 return s->init(
ctx,
s->params);
373 IplImage inimg, outimg;
384 s->end_frame_filter(
ctx, &inimg, &outimg);
392 #define OFFSET(x) offsetof(OCVContext, x)
393 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
421 .priv_class = &ocv_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVPixelFormat
Pixel format.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx)
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...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Filter name.
A link between two filters.
static av_cold void dilate_uninit(AVFilterContext *ctx)
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...
AVFILTER_DEFINE_CLASS(ocv)
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static av_cold int init(AVFilterContext *ctx)
int(* init)(AVFilterContext *ctx, const char *args)
static void smooth_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FILTER_INPUTS(array)
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static const AVFilterPad avfilter_vf_ocv_outputs[]
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
void(* uninit)(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int(* init)(AVFilterContext *ctx, const char *args)
#define FILTER_PIXFMTS(...)
static av_cold int dilate_init(AVFilterContext *ctx, const char *args)
static void fill_iplimage_from_frame(IplImage *img, const AVFrame *frame, enum AVPixelFormat pixfmt)
static av_cold void uninit(AVFilterContext *ctx)
static av_const int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
static void erode_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
static void dilate_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
enum AVPixelFormat pixfmt
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static void fill_frame_from_iplimage(AVFrame *frame, const IplImage *img, enum AVPixelFormat pixfmt)
static const AVFilterPad avfilter_vf_ocv_inputs[]
int h
agreed upon image height
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
void(* uninit)(AVFilterContext *ctx)
void(* end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename, void *log_ctx)
static float smooth(DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifo *values)
#define FILTER_OUTPUTS(array)
void(* end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static const OCVFilterEntry ocv_filter_entries[]
static av_cold int smooth_init(AVFilterContext *ctx, const char *args)
static const AVOption ocv_options[]
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
static int dilate(IPlane *g, IPlane *f, chord_set *SE, LUT *Ty)