No detection with webcam mode
tonginleong opened this issue · 9 comments
I tried the normal and v4-tiny model with demo_webcam.py
Everything is at default but no detection can be seen...not a single one, and of coz I tried different angles and stuff but no avail.
I am also a follower of yolov4 btw
Try this piece of code
import cv2
import argparse
from yolo import YOLO
arg = argparse.ArgumentParser()
arg.add_argument("-d", "--device", default=0, help="Device to use")
arg.add_argument("-s", "--size", default=416, help="Yolo input size")
arg.add_argument("-c", "--confidence", default=0.4, help="Confidence for yolo")
args = arg.parse_args()
yolo = YOLO(
"models/cross-hands-yolov4-tiny.cfg",
"models/cross-hands-yolov4-tiny.weights",
"hand",
)
yolo.size = int(args.size)
yolo.confidence = float(args.confidence)
print("starting webcam.")
cv2.namedWindow("preview")
cap = cv2.VideoCapture(args.device)
while True:
if cap.isOpened():
ret, frame = cap.read()
if not ret:
break
width, height, inference_time, results = yolo.inference(frame)
cv2.putText(
frame,
f"{round(1/inference_time,2)}) FPS",
(15, 15),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
(0, 255, 255),
2,
)
for detection in results:
id, name, confidence, x, y, w, h = detection
cx = x + (w / 2)
cy = y + (h / 2)
color = (0, 255, 255)
cv2.rectangle(frame, (x, y), (x + w, y + h), color, 2)
text = "%s (%s)" % (name, round(confidence, 2))
cv2.putText(
frame, text, (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2
)
cv2.imshow("preview", frame)
key = cv2.waitKey(1)
if key == 27:
break
cv2.destroyAllWindows()
cap.release()
@tonginleong Yes you are right, by mistake I merged a PR #10 which breaks the detection.
Fix is uploaded, would be great if you could give me a quick feedback.
glad i could help
@souravrs999 The code you posted did not fix the issue, I had to replace the hand-counting mechanism (a939fbe).
@souravrs999 The code you posted did not fix the issue, I had to replace the hand-counting mechanism (a939fbe).
It does work I removed the whole handcounting logic which was causing the issue
yep, the code is working fine now with the cross-hands.weights and its cfg, thank you.
I dont seem to be able to get it work with v4-tiny, but that is not much of a concern for me.
I met the same problem, it didnt work with v4-tiny. the results length is always zero. How could I fix this problem?
Without an example image I am not able to help you. The v4-tiny seems to work on my machine. Have you tried lowering the confidence threshold?
python demo_webcam.py -n v4-tiny -c 0.1
But what I can say is that the v4-tiny model does not work as good as the other models on webcam images if you are very close to the webcam. The network did maybe overfit a bit while training.