我尝试实施 Sharr过滤器+去除噪音。这是我的代码:
import sys
import numpy as np
import cv2
import math
filename = sys.argv[1]
cap = cv2.VideoCapture(filename)
cap.set(cv2.cv.CV_CAP_PROP_POS_MSEC, 300000)
scale = 1
delta = 0
ddepth = cv2.CV_16S
while(True):
success, img = cap.read()
img = cv2.GaussianBlur(img,(3,3),0)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#Scharr filter
scharr_grad_x = cv2.Scharr(gray,ddepth,1,0)
scharr_grad_y = cv2.Scharr(gray,ddepth,0,1)
scharr_abs_grad_x = cv2.convertScaleAbs(scharr_grad_x)
scharr_abs_grad_y = cv2.convertScaleAbs(scharr_grad_y)
#remove noize after scharr filter
scharr = np.hypot(scharr_abs_grad_x, scharr_abs_grad_y)
mean = np.mean(scharr);
scharr[scharr <= mean] = 0;
scharr = cv2.add(scharr_abs_grad_x,scharr_abs_grad_y)
cv2.imshow('scharr',scharr)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
我发现了numpy的想法。但我无法纠正制定解决方案。 结果将如下面的屏幕截图所示。
如何在我的代码中实现它?