侧边栏壁纸
博主头像
996worker

祇園精舎の鐘の聲, 諸行無常の響き有り。

  • 累计撰写 201 篇文章
  • 累计创建 48 个标签
  • 累计收到 8 条评论

目 录CONTENT

文章目录

Using Canny & Hough algo to find the intersection

996worker
2021-07-03 / 0 评论 / 0 点赞 / 259 阅读 / 1,388 字
温馨提示:
本文最后更新于 2021-07-24,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1. Threshold -> RGB to Gray

2. Denoise and filtering

Mean filtering: good effect on Gaussian noise. But poor in pepper noise.
Box filtering: similar with the one above (need normalization).
Gaussian filtering: high weight to the middle.
Median filtering: good for pepper noise.
Another way to deal with the small white noise:
FindContours, then blacken the area with small size.

3. Morphological Processing

    cv2.erode(img, kernel1,iterations=1)
    cv2.dilate(erotion, kernel2, iterations=1)
    # open:erode then dilate
    open_calc = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel1)
    # colse: dilate then erode
    close_calc = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel1)

4. Canny edge detection

     edge_img = cv2.Canny(gray, 80, 150)

5. Hough: find lines. We could group these lines. Those with similar slopes and intercepts are divided into the same group. Here are my examples:

     # Hough直线检测
         lines = cv2.HoughLines(edge_img, 1, np.pi / 180, 36)
         lines1 = lines[:, 0, :]  # 提取为为二维

         debug_img = self.img_color.copy()
         # 从左上到右下的线组
         line_group_lt2rb = []

         # 从左下到右上的线组
         line_group_lb2rt = []
         for rho, theta in lines1[:]:
             a = np.cos(theta)
             b = np.sin(theta)
             x0 = a * rho
             y0 = b * rho
             x1 = int(x0 + 1000 * (-b))
             y1 = int(y0 + 1000 * (a))
             x2 = int(x0 - 1000 * (-b))
             y2 = int(y0 - 1000 * (a))

             # 整理线组 - 按角度分类
             k = (int(y2) - int(y1)) / (int(x2) - int(x1))
             # -17 deg ~ -78 deg (opencv坐标系和传统坐标系关于x对称,斜率相反)
             if 0 < k < 1.2:
                 line_group_lt2rb.append([(x1, y1), (x2, y2)])

             # 0 ~ 50 deg
             elif -0.3 > k > -5:
                 line_group_lb2rt.append([(x1, y1), (x2, y2)])


6. Find the center lines of two parallel yellow lines. The intersection point of the two center lines is the intersection point.

0

评论区