Go to the documentation of this file.
46 #define OFFSET(x) offsetof(DnnDetectContext, dnnctx.x)
47 #define OFFSET2(x) offsetof(DnnDetectContext, x)
48 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
51 #if (CONFIG_LIBTENSORFLOW == 1)
54 #if (CONFIG_LIBOPENVINO == 1)
68 float conf_threshold =
ctx->confidence;
69 int proposal_count =
output->height;
70 int detect_size =
output->width;
71 float *detections =
output->data;
83 for (
int i = 0;
i < proposal_count; ++
i) {
84 float conf = detections[
i * detect_size + 2];
85 if (conf < conf_threshold) {
104 for (
int i = 0;
i < proposal_count; ++
i) {
105 int av_unused image_id = (
int)detections[
i * detect_size + 0];
106 int label_id = (
int)detections[
i * detect_size + 1];
107 float conf = detections[
i * detect_size + 2];
108 float x0 = detections[
i * detect_size + 3];
109 float y0 = detections[
i * detect_size + 4];
110 float x1 = detections[
i * detect_size + 5];
111 float y1 = detections[
i * detect_size + 6];
115 if (conf < conf_threshold) {
122 bbox->
h = (
int)(y1 *
frame->height) - bbox->
y;
127 if (
ctx->labels && label_id < ctx->label_count) {
134 if (nb_bboxes == 0) {
146 float conf_threshold =
ctx->confidence;
147 float *conf, *position, *label_id, x0, y0, x1, y1;
155 position =
output[3].data;
156 label_id =
output[2].data;
164 for (
int i = 0;
i < proposal_count; ++
i) {
165 if (conf[
i] < conf_threshold)
170 if (nb_bboxes == 0) {
183 for (
int i = 0;
i < proposal_count; ++
i) {
184 y0 = position[
i * 4];
185 x0 = position[
i * 4 + 1];
186 y1 = position[
i * 4 + 2];
187 x1 = position[
i * 4 + 3];
191 if (conf[
i] < conf_threshold) {
198 bbox->
h = (
int)(y1 *
frame->height) - bbox->
y;
203 if (
ctx->labels && label_id[
i] <
ctx->label_count) {
210 if (nb_bboxes == 0) {
234 for (
int i = 0;
i <
ctx->label_count;
i++) {
237 ctx->label_count = 0;
253 while (!feof(file)) {
256 if (!fgets(buf, 256, file)) {
260 line_len = strlen(buf);
262 int i = line_len - 1;
263 if (buf[
i] ==
'\n' || buf[
i] ==
'\r' || buf[
i] ==
' ') {
301 switch(backend_type) {
303 if (output_nb != 4) {
305 but get %d instead\n", output_nb);
310 if (output_nb != 1) {
312 but get %d instead\n", output_nb);
337 if (
ctx->labels_filename) {
372 *out_pts = in_frame->
pts +
pts;
424 int64_t out_pts =
pts;
458 .
name =
"dnn_detect",
466 .priv_class = &dnn_detect_class,
static enum AVPixelFormat pix_fmts[]
AVPixelFormat
Pixel format.
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
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 FilteringContext * filter_ctx
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
#define FILTER_PIXFMTS_ARRAY(array)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
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
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).
AVFILTER_DEFINE_CLASS(dnn_detect)
static int read_detect_label_file(AVFilterContext *context)
static av_cold int dnn_detect_init(AVFilterContext *context)
#define AV_LOG_VERBOSE
Detailed information.
static const AVFilterPad dnn_detect_inputs[]
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
const char * name
Filter name.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
static int dnn_detect_post_proc_ov(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx)
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE
char detect_label[AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE]
Detect result with confidence.
void * priv
private data for use by the filter
static av_cold void dnn_detect_uninit(AVFilterContext *context)
A filter pad used for either input or output.
static av_always_inline AVDetectionBBox * av_get_detection_bbox(const AVDetectionBBoxHeader *header, unsigned int idx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
int ff_dnn_set_detect_post_proc(DnnContext *ctx, DetectPostProc post_proc)
static void free_detect_labels(DnnDetectContext *ctx)
DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame)
const AVFilter ff_vf_dnn_detect
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int av_usleep(unsigned usec)
Sleep for a period of time.
#define AV_PIX_FMT_GRAYF32
#define FILTER_INPUTS(array)
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 keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Describe the class of an AVClass context structure.
static int dnn_detect_activate(AVFilterContext *filter_ctx)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int ff_dnn_flush(DnnContext *ctx)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
AVDetectionBBoxHeader * av_detection_bbox_create_side_data(AVFrame *frame, uint32_t nb_bboxes)
Allocates memory for AVDetectionBBoxHeader, plus an array of.
#define DNN_COMMON_OPTIONS
DNNBackendType backend_type
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static AVRational av_make_q(int num, int den)
Create an AVRational.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
AVFilterContext * src
source filter
static const uint8_t header[24]
FF_FILTER_FORWARD_WANTED(outlink, inlink)
static const AVOption dnn_detect_options[]
static int dnn_detect_flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
static int dnn_detect_post_proc(AVFrame *frame, DNNData *output, uint32_t nb, AVFilterContext *filter_ctx)
#define i(width, name, range_min, range_max)
static int check_output_nb(DnnDetectContext *ctx, DNNBackendType backend_type, int output_nb)
const char * name
Pad name.
FILE * avpriv_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
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
AVRational detect_confidence
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
int x
Distance in pixels from the left/top edge of the frame, together with width and height,...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
char * av_strdup(const char *s)
Duplicate a string.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Structure to hold side data for an AVFrame.
#define FILTER_OUTPUTS(array)
int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static const AVFilterPad dnn_detect_outputs[]
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
void ff_dnn_uninit(DnnContext *ctx)
static av_cold int uninit(AVCodecContext *avctx)
static int dnn_detect_post_proc_tf(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx)
int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
@ AV_FRAME_DATA_DETECTION_BBOXES
Bounding boxes for object detection and classification, as described by AVDetectionBBoxHeader.