Changed several bug:
1, the stack by the global variable into a local variable, fixed the starting point of the same problem.
2, the low-pass filter to a high pass filter, the correction of the problem of too much data is pushed onto the stack.
f = np.fft.fft2(new_gray_array) rows,cols=f.shape f[0:fftadd]=0 f[rows-fftadd:rows]=0
Question: The new algorithm is influenced by light
Use a for loop to write two rectangles, making some good accuracy
leng = len(s.stack) if leng !=0: if(leng > 4): for i in range(1, int(leng / 2)+2, int(leng / 2)): s_1 = list(s.stack[i]) s_2 = list(s.stack[i + int(leng / 2)-2]) x = s_1[0] y = s_1[1] x_1 = s_2[0] y_1 = s_2[1] cv2.rectangle(frame, (y, x), (y_1, x_1), (255, 255, 0), 2) # 绘制矩形 print(x, y, x_1, y_1) print(1) cv2.imshow("fps", frame) else: s_1 = list(s.stack[0]) s_2 = list(s.stack[leng - 1]) x = s_1[0] y = s_1[1] x_1 = s_2[0] y_1 = s_2[1] cv2.rectangle(frame, (y, x), (y_1, x_1), (255, 255, 0), 2) # 绘制矩形 print(x, y, x_1, y_1) cv2.imshow("fps", frame)
Noise is still very large, consider whether or not you want to get some de-noising function to make the image more smooth.