Go to the documentation of this file.
48 #define OFFSET(x) offsetof(FOCContext, x)
49 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
83 for(y = 0; y <
frame->height; y++) {
84 for(x = 0; x <
frame->width; x++) {
107 const uint8_t *odat = obj ->
data[0];
108 const uint8_t *hdat = haystack->
data[0] + offx + offy * haystack->
linesize[0];
111 for(y = 0; y < obj->
height; y++) {
112 for(x = 0; x < obj->
width; x++) {
117 oo_sum_v += o_v * o_v;
118 hh_sum_v += h_v * h_v;
119 oh_sum_v += o_v * h_v;
124 o_sigma = n*oo_sum_v - o_sum_v*(
int64_t)o_sum_v;
125 h_sigma = n*hh_sum_v - h_sum_v*(
int64_t)h_sum_v;
127 if (o_sigma == 0 || h_sigma == 0)
130 c = (n*oh_sum_v - o_sum_v*(
int64_t)h_sum_v) / (sqrt(o_sigma)*sqrt(h_sigma));
148 static float search(
FOCContext *foc,
int pass,
int maxpass,
int xmin,
int xmax,
int ymin,
int ymax,
int *best_x,
int *best_y,
float best_score)
152 if (pass + 1 <= maxpass) {
154 search(foc, pass+1, maxpass, xmin>>1, (xmax+1)>>1, ymin>>1, (ymax+1)>>1, &sub_x, &sub_y, 2.0);
155 xmin =
FFMAX(xmin, 2*sub_x - 4);
156 xmax =
FFMIN(xmax, 2*sub_x + 4);
157 ymin =
FFMAX(ymin, 2*sub_y - 4);
158 ymax =
FFMIN(ymax, 2*sub_y + 4);
161 for (y = ymin; y <= ymax; y++) {
162 for (x = xmin; x <= xmax; x++) {
164 if (score < best_score) {
189 best_score =
search(foc, 0, 0,
194 &best_x, &best_y, 2.0);
197 &best_x, &best_y, best_score);
214 best_x, best_y, best_score);
218 snprintf(buf,
sizeof(buf),
"%f", best_score);
297 .priv_class = &find_rect_class,
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
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
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.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static AVFrame * downscale(AVFrame *in)
const char * name
Filter name.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Link properties exposed to filter code, but not external callers.
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_OUTPUTS(array)
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
AVFILTER_DEFINE_CLASS(find_rect)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static FilterLink * ff_filter_link(AVFilterLink *link)
static av_cold int init(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const AVFilterPad foc_inputs[]
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
int ff_load_image(uint8_t *data[4], int linesize[4], int *w, int *h, enum AVPixelFormat *pix_fmt, const char *filename, void *log_ctx)
Load image from filename and put the resulting image in data.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFrame * haystack_frame[MAX_MIPMAPS]
const AVFilter ff_vf_find_rect
#define AV_LOG_INFO
Standard information.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#define i(width, name, range_min, range_max)
static int config_input(AVFilterLink *inlink)
const char * name
Pad name.
#define FILTER_PIXFMTS(...)
static float search(FOCContext *foc, int pass, int maxpass, int xmin, int xmax, int ymin, int ymax, int *best_x, int *best_y, float best_score)
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
AVFrame * needle_frame[MAX_MIPMAPS]
static float compare(const AVFrame *haystack, const AVFrame *obj, int offx, int offy)
@ AV_OPT_TYPE_INT
Underlying C type is int.
AVDictionary * metadata
metadata.
static av_cold void uninit(AVFilterContext *ctx)
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
static const AVOption find_rect_options[]
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...