AstroPy basic



Lesson: Hough transform with OpenCV; 利用霍夫變換與OpenCV用來辨別找出物件中的特徵


HT.py

import cv2
import numpy as np;
 
img = cv2.imread('FRB.png');
cv2.imshow("orginal img", img)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY); # cvtColor is a color convert function, the fist seqence is picture, second is convert mode  
cv2.imshow("orgial gray", gray)
edges = cv2.Canny(gray, 130, 220); # the first sequece is picture, the second and third squence are min and Max threshold
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 30, maxLineGap=10); #void HoughLines(InputArray image, OutputArray lines, double rho, double theta, int threshold, double srn=0, double stn=0)
for line in lines:
    x1, y1, x2, y2 = line[0]
    cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 1)
 
cv2.imshow("Edges", edges)
cv2.imshow("Image with HoughLines", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
result
Original fast radio burst image with 2 fake line
s


The Hough lines with original image
The Hough lines with original image