我正在尝试制作一个跟踪地面上黑色物体的项目,这里有一个恶劣的沙漠阳光环境,我试图进行一些试验,但它不起作用。我尝试将图像中的黑色像素转换为红色,因为红色像素很容易跟踪(更高的强度),但它不会产生我想要的结果。我尝试反转图像(将黑色转换为白色,将白色转换为黑色),但它也没有提供所需的结果。那么任何想法?
以下是代码:
import cv2
import numpy as np
import os
from matplotlib import pyplot as plt
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret,frame = cap.read()
warp = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
ORANGE_MIN = np.array([40, 40, 60], np.uint8)
ORANGE_MAX = np.array([50, 70, 80], np.uint8)
hsv_img = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
Conv_hsv_Gray = cv2.cvtColor(hsv_img, cv2.COLOR_BGR2GRAY)
imf = np.float32(Conv_hsv_Gray) / 255.0 # float conversion/scale
Desc = cv2.dct(imf)
sub_to = Desc[0, 0]
print sub_to
result_frame = Desc - sub_to
Fitr = cv2.blur(result_frame, (1, 1))
Filter2 = cv2.GaussianBlur(Desc, (1, 1), 0)
iddt1 = cv2.idct(Fitr)
iddt2 = cv2.idct(Filter2)
framethreshed = cv2.inRange(hsv_img, ORANGE_MIN, ORANGE_MAX)
ret, mask = cv2.threshold(Conv_hsv_Gray, 100, 150, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(warp)
mask = cv2.erode(mask, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2)
res = cv2.bitwise_and(iddt1, iddt1, mask=mask)
cv2.imwrite('output2.jpg', framethreshed)
cv2.imshow("imgOriginal(1)", frame) # show windows
cv2.imshow("Masking res(3)", res) # show windows
cv2.imshow("mask_inv)", mask_inv) # show windows
if cv2.waitKey(60) & 0xFF == ord('q'):
break
cap.release()