【发布时间】:2019-05-08 02:36:52
【问题描述】:
两个盒子相互接触时如何保存图像,我希望当边界框面接触香烟边界框时,图像将作为一个整体保存。
这是代码:
import cv2
import numpy as np
cigarette = cv2.CascadeClassifier('classifier/cigarette-cascade.xml')
faced = cv2.CascadeClassifier('classifier/face-detect.xml')
cam = cv2.VideoCapture(0)
while True:
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faced.detectMultiScale(gray, 1.3, 5)
cigarettes = cigarette.detectMultiScale(gray, 1.3, 5)
for x,y,w,h in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
for (x, y, w, h) in cigarettes:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 2)
cv2.imshow('test', img)
k = cv2.waitKey(1) & 0xff
if k == 27:
break
cv2.destroyAllWindows()
【问题讨论】:
-
你可以使用 (RectA & RectB).area() 来判断两个区域是否相交
-
你能给我举个例子吗?