我提取了对象的轮廓,然后在对象周围绘制了一个旋转的矩形(带有角度的边界框)。
image, contours, hierarchy = cv2.findContours(image,mode = cv2.RETR_TREE,method = cv2.CHAIN_APPROX_SIMPLE)
rect = cv2.minAreaRect(contours[0])
rectangle vertices with angle :
((1395.578369140625, 117.2541732788086),
(56.1618537902832, 148.37057495117188),
-51.745582580566406)
box = cv2.boxPoints(rect)
bounding box vertices
array([[1436, 185],
[1319, 93],
[1354, 49],
[1471, 141]])
我想实现一种算法,该算法在边界框中绘制滑动窗口以检测每个窗口区域中的像素数是否小于100像素。
# Choose the number of sliding windows
nwindows = 9
# Set height of windows
window_height = np.int((box[0][0]-box[1][0])//9)
# Set the width of the windows +/- margin
margin = 20
# Identify the x and y positions of all nonzero pixels in the image
nonzero = img.nonzero()
nonzerox = np.array(nonzero[1])
nonzeroy = np.array(nonzero[0])
# Current positions to be updated for each window
x_current = ?
# Set minimum number of pixels found
minpix = 50
# Create empty lists to receive pixel indices
inds = []