简体   繁体   English

OpenCV-识别视频帧上的常规模式

[英]OpenCV - Identify regular patterns on video frame

I need to identify striped patterns on video sequences. 我需要确定视频序列上的条纹图案。

I'm trying to use the OpenCV Houghlines function to detect the lines of the pattern. 我正在尝试使用OpenCV Houghlines函数来检测模式的线条。 Once i have the Houghlines (GREEN_lines) i need to know which are the lines closest to each other and discard all the others. 一旦有了Houghlines (GREEN_lines),我就需要知道哪些是最接近的线,并丢弃所有其他的线。 I also need to know how many pairs of dark(RED_line) and light(BLUE_line) stripes are on the image. 我还需要知道图像上有几对深色(RED_line)和浅色(BLUE_line)条纹。

Then i need to to know the average luminance of the area inside each "box" formed by the Houghlines. 然后,我需要知道由霍夫线形成的每个“盒子”内部区域的平均亮度。

检测方案

The pattern can appear in video frames on different angles (image on the right). 该图案可以以不同角度出现在视频帧中(右图)。

Any suggestions? 有什么建议么?

Suppose the lines obtained from applying the Hough Transform are L1, L2, ..., Lk, for k lines that are detected. 对于检测到的k条线,假设通过应用霍夫变换获得的线为L1,L2,...,Lk。 Let each line, Li be represented by 2 points, ((x1i, y1i), (x2i, y2i)). 让每条线Li用2个点表示((x1i,y1i),(x2i,y2i))。

First, determine which lines are parallel, and which are perpendicular to each other. 首先,确定哪些线是平行的,哪些线是相互垂直的。 You can do this by computing the dot product between the unit direction vector for each pair of line. 您可以通过计算每对线的单位方向向量之间的点积来实现。 Pairs of lines which are perpendicular to each other will have dot product 0 (or close to 0 since you detected lines may not be exactly perpendicular due to noise/numerical errors), and dot product close to 1 if they are parallel. 相互垂直的线对的点积为0(或接近于0,因为您检测到的线可能由于噪声/数字误差而并非完全垂直),而如果点平行,则点积接近于1。

Once you know which lines are parallel, and which are perpendicular, you can sort them based on the x-coordinates (for the "vertical" lines) or y-coordinates (for the 2 "horizontal" lines). 一旦知道了哪些线是平行的,哪些线是垂直的,就可以基于x坐标(对于“垂直”线)或y坐标(对于2条“水平”线)对它们进行排序。

Now you will need to solve for the intersecting points between each "vertical" line and each "horizontal" line, which can be obtained using a little algebra and geometry. 现在,您需要求解每条“垂直”线与每条“水平”线之间的相交点,这可以使用少量的代数和几何来获得。

With these points and the lines, you can create a mask to compute the desired values in the image (for eg, the luminance within each box). 使用这些点和线,您可以创建一个遮罩以计算图像中的所需值(例如,每个框内的亮度)。 The sorted lines will also tell you which lines are closest to each other. 排序的行还将告诉您哪些行彼此最接近。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM