results = self.model_predict(frame) dets = [] if len(results) == 0: pass else: for index, row in results.iterrows(): class_ids = row['class'] scores = float(row['confidence']) x1 = int(row['xmin']) y1 = int(row['ymin']) x2 = int(row['xmax']) y2 = int(row['ymax']) cx = int((x1 + x2)/2) cy = int((y1 + y2)/2) pt_center = (cx,cy) dist = cv2.pointPolygonTest(pts, pt_center, False) if dist > 0: print('在内部') dets.append([x1,y1,x2,y2,scores]) else: print('在外部') 找出为外部的,删除result值
时间: 2024-02-10 20:32:26 浏览: 81
您的问题是如何找出为外部的并删除result值?
在上述代码中,找出为外部的结果是通过计算目标中心点到多边形的距离(dist)来实现的,如果距离大于0,则说明目标不在多边形内部,需要将其删除。可以使用以下代码来实现:
```
to_delete = []
for index, row in results.iterrows():
class_ids = row['class']
scores = float(row['confidence'])
x1 = int(row['xmin'])
y1 = int(row['ymin'])
x2 = int(row['xmax'])
y2 = int(row['ymax'])
cx = int((x1 + x2)/2)
cy = int((y1 + y2)/2)
pt_center = (cx,cy)
dist = cv2.pointPolygonTest(pts, pt_center, False)
if dist > 0:
print('在外部')
to_delete.append(index)
else:
print('在内部')
results = results.drop(to_delete)
```
这段代码会遍历所有的结果,如果发现目标不在多边形内部,则将其对应的索引添加到一个列表中,遍历完所有结果后,再将这些索引对应的结果从results中删除。
阅读全文