[FFmpeg-devel] [Patch] vf_edgedetect: properly implement double_threshold()

Valery Kot valery.kot at gmail.com
Sat Jun 20 02:24:43 EEST 2020


>
> > vf_edgedetect video filter implements Canny algorithm
> > (https://en.wikipedia.org/wiki/Canny_edge_detector)
> >
> > Important part of this algo is the double threshold step: pixels above
> > "high" threshold being kept, pixels below "low" threshold dropped,
> > pixels in between kept if they are attached to "high" pixels.
> >
> > This is implemented in the double_threshold() function. However,
> > condition to start checking attached pixels, as it is now and as it
> > was in FFmpeg since 2012, only allows checking on the boundary, not
> > inside the video. It is a very lucky coincidence that those boundary
> > pixels are always 0, otherwise following lines would be reading
> > outside of the buffer.
> >
> > As it is now, double_threshold() only implements "high" thresholding.
> > As a result, edges are either noisy or fragmented, depending on "high"
> > threshold selection; "low" threshold is simply ignored.
> >
> > Attached one char patch fixes this.
> >
> > Please review.
>
> Looks indeed like the condition is wrong.
>
> I say looks because I did only look and didn't do actual testing.
>
> I hope you will answer my question anyway: Does your patch completely
> fix the problem or is it sacrificing the treatment of the outer most
> pixels?
>

>
Hi Alexander,
Outer pixels are already set to 0 (line 333, memset(tmpbuf, 0, inlink->w
<https://ffmpeg.org/doxygen/2.7/structAVFilterLink.html#a08e3e25929bb29d5f6ef768343ff7f57>
* inlink->h
<https://ffmpeg.org/doxygen/2.7/structAVFilterLink.html#a1efd10db9d097b6d27054da46e06e133>
);)
This  is correct, as it is not possible to properly calculate gradient
there.
Patch fixes handling of inner pixels and changes nothing for outer pixels.


More information about the ffmpeg-devel mailing list