如何检查 cv2.rectangle 是否位于 opencv python 中的 cv2.rectangle 内
How to check if cv2.rectangle lies inside cv2.rectangle in opencv python
我有一个矩形坐标
cv2.rectangle(image, (245, 158), (721, 924), color, 2)
它标识了人(主要对象)。
我还有一个头盔坐标,它在我的第一个矩形内部检测到
cv2.rectangle(image, (415, 180), (650, 345), color, 2)
现在在代码中,我必须检查在主矩形内识别了多少个矩形的条件(人是我的主要对象)。
谁能给我推荐个好方法。请。谢谢
我想既然你有坐标你就可以检查头盔的坐标是否位于人的坐标中间
px1, py1, px2, py2 = 245, 158, 721, 924
hx1, hy1, hx2, hy2 = 415, 180, 650, 345
if hx1 >= px1 and hy1 >= py1 and hx2 <= px2 and hy2 <=py2:
# do whatever
如果你想利用 cv2
并找到它消失的区域,那么你可以使用与你的图像大小相同的空白 NumPy 零数组,用白色绘制人正方形,执行它的倒数,然后与另一个相同大小的数组进行异或运算,该数组的头盔画成白色。这样你就会得到人外的区域。
import numpy as np
import cv2
h, w = image[:2]
p_img = np.zeros((w, h), dtype=np.uint8)
h_img = np.zeros((w, h), dtype=np.uint8)
cv2.rectangle(p_img, (245, 158), (721, 924), (255, 255, 255), -1)
cv2.rectangle(h_img, (415, 180), (650, 345), (255, 255, 255), -1)
p_img = cv2.bitwise_not(p_img)
res = cv2.bitwise_xor(p_img, h_img)
我有一个矩形坐标
cv2.rectangle(image, (245, 158), (721, 924), color, 2)
它标识了人(主要对象)。
我还有一个头盔坐标,它在我的第一个矩形内部检测到
cv2.rectangle(image, (415, 180), (650, 345), color, 2)
现在在代码中,我必须检查在主矩形内识别了多少个矩形的条件(人是我的主要对象)。
谁能给我推荐个好方法。请。谢谢
我想既然你有坐标你就可以检查头盔的坐标是否位于人的坐标中间
px1, py1, px2, py2 = 245, 158, 721, 924
hx1, hy1, hx2, hy2 = 415, 180, 650, 345
if hx1 >= px1 and hy1 >= py1 and hx2 <= px2 and hy2 <=py2:
# do whatever
如果你想利用 cv2
并找到它消失的区域,那么你可以使用与你的图像大小相同的空白 NumPy 零数组,用白色绘制人正方形,执行它的倒数,然后与另一个相同大小的数组进行异或运算,该数组的头盔画成白色。这样你就会得到人外的区域。
import numpy as np
import cv2
h, w = image[:2]
p_img = np.zeros((w, h), dtype=np.uint8)
h_img = np.zeros((w, h), dtype=np.uint8)
cv2.rectangle(p_img, (245, 158), (721, 924), (255, 255, 255), -1)
cv2.rectangle(h_img, (415, 180), (650, 345), (255, 255, 255), -1)
p_img = cv2.bitwise_not(p_img)
res = cv2.bitwise_xor(p_img, h_img)