47#define OFFSET(x) offsetof(FOCContext, x)
48#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
84 for(y = 0; y < h2; y++) {
85 for(x = 0; x < w2; x++) {
97 for(y = 0; y <
frame->height; y++) {
98 int yd = y < h2 ? in->
linesize[0] : 0;
100 for(; x <
frame->width; x++) {
124 const uint8_t *odat = obj ->
data[0];
125 const uint8_t *hdat = haystack->
data[0] + offx + offy * haystack->
linesize[0];
128 for(y = 0; y < obj->
height; y++) {
129 for(x = 0; x < obj->
width; x++) {
134 oo_sum_v += o_v * o_v;
135 hh_sum_v += h_v * h_v;
136 oh_sum_v += o_v * h_v;
141 o_sigma = n*oo_sum_v - o_sum_v*(
int64_t)o_sum_v;
142 h_sigma = n*hh_sum_v - h_sum_v*(
int64_t)h_sum_v;
144 if (o_sigma == 0 || h_sigma == 0)
147 c = (n*oh_sum_v - o_sum_v*(
int64_t)h_sum_v) / (sqrt(o_sigma)*sqrt(h_sigma));
152static 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)
156 if (pass + 1 <= maxpass) {
158 search(foc, pass+1, maxpass, xmin>>1, (xmax+1)>>1, ymin>>1, (ymax+1)>>1, &sub_x, &sub_y, 2.0);
159 xmin =
FFMAX(xmin, 2*sub_x - 4);
160 xmax =
FFMIN(xmax, 2*sub_x + 4);
161 ymin =
FFMAX(ymin, 2*sub_y - 4);
162 ymax =
FFMIN(ymax, 2*sub_y + 4);
165 for (y = ymin; y <= ymax; y++) {
166 for (x = xmin; x <= xmax; x++) {
168 if (score < best_score) {
193 if (xmin > xmax || ymin > ymax)
202 best_score =
search(foc, 0, 0,
207 &best_x, &best_y, 2.0);
209 best_score =
search(foc, 0, foc->
mipmaps - 1, xmin, xmax, ymin, ymax,
210 &best_x, &best_y, best_score);
227 best_x, best_y, best_score);
231 snprintf(buf,
sizeof(buf),
"%f", best_score);
293 .p.name =
"find_rect",
296 .p.priv_class = &find_rect_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFFilter ff_vf_find_rect
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define i(width, name, range_min, range_max)
static __device__ float fabs(float a)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ 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...
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
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.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int ff_load_image(struct AVFrame **outframe, const char *filename, void *log_ctx)
Load image from filename and put the resulting image in an AVFrame.
Miscellaneous utilities which make use of the libavformat library.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS(...)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
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).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVDictionary * metadata
metadata.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFrame * needle_frame[MAX_MIPMAPS]
AVFrame * haystack_frame[MAX_MIPMAPS]
Link properties exposed to filter code, but not external callers.
static AVFormatContext * ctx
static float compare(const AVFrame *haystack, const AVFrame *obj, int offx, int offy)
static AVFrame * downscale(AVFrame *in)
static const AVFilterPad foc_inputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption find_rect_options[]
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)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.