[英]Saving Metadata after object detection with opencv
I am fairly new to this topic but would like to safe the counts of "objects" found within my video, simply the raw counts of objects in each frame into a text file.我对这个主题相当陌生,但想保护在我的视频中找到的“对象”的计数,只需将每帧中对象的原始计数保存到文本文件中。 I have the following code that runs well, but 1) it does not safe the objects as images to my folder, which I dont understand, and 2) it would not / or where are the objects saved as metadata.我有以下运行良好的代码,但是 1)它不能将对象作为图像保存到我的文件夹中,我不明白,2)它不会/或者对象在哪里保存为元数据。 Any help in this regard?在这方面有什么帮助吗?
Here is the code:这是代码:
import cv2
#############################################
frameWidth = 640
frameHeight = 480
nPlateCascade = cv2.CascadeClassifier("Resources/haarcascades/haarcascade_fullbody.xml")
minArea = 200
color = (255, 0, 255)
###############################################
cap = cv2.VideoCapture("Resources/nyc.mp4")
cap.set(3, frameWidth)
cap.set(4, frameHeight)
cap.set(10, 150)
count = 0
while True:
success, img = cap.read()
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
numberPlates = nPlateCascade.detectMultiScale(imgGray, 1.1, 10)
for (x, y, w, h) in numberPlates:
area = w * h
if area > minArea:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 255), 2)
cv2.putText(img, "Object", (x, y - 5),
cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, color, 2)
imgRoi = img[y:y + h, x:x + w]
cv2.imshow("ROI", imgRoi)
cv2.imshow("Result", img)
if cv2.waitKey(1) and 0xFF == ord('s'):
cv2.imwrite("Resources/Output/" + str(count) + ".jpg", imgRoi)
cv2.rectangle(img, (0, 200), (640, 300), (0, 255, 0), cv2.FILLED)
cv2.putText(img, "Scan Saved", (150, 265), cv2.FONT_HERSHEY_DUPLEX,
2, (0, 0, 255), 2)
cv2.imshow("Result", img)
cv2.waitKey(500)
count += 1
if cv2.waitKey(1) and 0xFF == ord('s')
that's the issue right there.这就是问题所在。
and
is a logical/boolean operator and has lower precedence than ==
. and
是逻辑/布尔运算符,优先级低于==
。 what's written there means那里写的是什么意思
cv2.waitKey(1) and (0xFF == ord('s'))
I think you don't mean that.我想你不是那个意思。
You probably wanted the &
operator which is a bitwise operator (operates on integers) and has higher priority than ==
.您可能想要&
运算符,它是按位运算符(对整数进行运算)并且具有比==
更高的优先级。
cv2.waitKey(1) & 0xFF == ord('s') # is equivalent to
(cv2.waitKey(1) & 0xFF) == ord('s')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.