[Task]: Detection of video streams
EricXuenew opened this issue · comments
What is the motivation for this task?
I would like to achieve the function to detect from video streams. Now I can only put pictures into the Anomalib.
Describe the solution you'd like
How to realize the detection of video streams, such as connecting a camera for real-time detection.
Additional context
No response
@EricXuenew, are you interested to know how this is done, or do you want anomalib to support this by default?
@EricXuenew, are you interested to know how this is done, or do you want anomalib to support this by default?
Thanks for your reply! I would like to know if connecting to a camera is now possible with anomalib?
Also I tried to put in a video, because I see that the code has the option to support video_PATH, but I input a video and get an error!
I would like to implement these features in anomalib v0.7.0, is it feasible, looking forward to your reply!
You can split frames from the video and do inference
You can split frames from the video and do inference
Like pre-processing it? Does Anomalib have custom algorithm to accomplish it? For example, changing some parameter in the padim.yaml.
@EricXuenew, you might need to write your own script to detect from frames. It would be something like this -- though you might need do double check the code as it just a pseudo-code
def main():
# Initialize the webcam (use 0 as the device index to select the default webcam)
cap = cv2.VideoCapture(0)
# Check if the webcam is opened correctly
if not cap.isOpened():
print("Error: Could not open webcam.")
return
# TODO: Instantiate your inferencer - OpenVINO or Torch Inferencer from anomalib.
# inferencer = OpenVINOInferencer(path=args.weights, metadata=args.metadata, device=args.device)
# inferencer = TorchInferencer(path=args.weights, device=args.device)
while True:
# Capture frame-by-frame
ret, frame = cap.read()
if not ret:
print("Error: Can't receive frame (stream end?). Exiting ...")
break
# Make a prediction using the inferencer
prediction = inferencer.predict(frame)
# Alternatively, you could also use `Engine.predict()` method as well.
# Display the prediction result on the frame (customize as needed)
cv2.putText(frame, str(prediction), (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
# Display the resulting frame
cv2.imshow('Frame', frame)
# Break the loop when 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()
You could tweak it however you want to. I'm moving this to the Q&A in discussions sections. Feel free to continue there.