[Task]: Detection of video streams #1903
Replies: 6 comments 1 reply
-
@EricXuenew, are you interested to know how this is done, or do you want anomalib to support this by default? |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply! I would like to know if connecting to a camera is now possible with anomalib? |
Beta Was this translation helpful? Give feedback.
-
I would like to implement these features in anomalib v0.7.0, is it feasible, looking forward to your reply! |
Beta Was this translation helpful? Give feedback.
-
You can split frames from the video and do inference |
Beta Was this translation helpful? Give feedback.
-
Like pre-processing it? Does Anomalib have custom algorithm to accomplish it? For example, changing some parameter in the padim.yaml. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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
Beta Was this translation helpful? Give feedback.
All reactions