-
-
Notifications
You must be signed in to change notification settings - Fork 16k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closing of Camera Module in offline recognition #12755
Comments
👋 Hello @Jayashankar-K, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution. If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it. If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results. RequirementsPython>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started: git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit. Introducing YOLOv8 🚀We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀! Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects. Check out our YOLOv8 Docs for details and get started with: pip install ultralytics |
@Jayashankar-K hello! It sounds like you're facing an issue with properly releasing the camera resource between iterations of your detection loop. To ensure the camera is released correctly, you should explicitly release the capture object at the end of each detection cycle. Here's a general approach you can follow:
Your loop might look something like this: cap = cv2.VideoCapture(0) # Initialize outside the loop
while True:
if condition_met:
# Perform detection using cap
# ...
cap.release() # Release after detection
cv2.destroyAllWindows() # Close any windows
# Reinitialize if needed
cap = cv2.VideoCapture(0)
# Other conditions or sleep to prevent tight looping Make sure that the If you continue to face issues, please provide a minimal code snippet that reproduces the problem, and we'll take a closer look. Remember to handle any exceptions and edge cases where the camera might not be initialized or released properly. For more detailed guidance, you can refer to our documentation at https://docs.ultralytics.com/yolov5/. Keep up the great work, and I hope this helps you resolve the issue! 😊 |
@glenn-jocher I have tried your solution but it does not work. here are my codes if you want to take a look 1- After my initial condition is met then i invoke the detection algorithm Then this code invokes detect.py program in which the major part of creating a camera module and detection process takes place. If i am able to successfully close the window then my project will be completed. Thank you for your help and support. |
@Jayashankar-K, I'm sorry to hear that the issue persists. Unfortunately, I cannot view the screenshots or external code links you've provided due to the guidelines of this platform. However, I can still offer some general advice. The error message you're seeing typically indicates that the camera resource is not being released properly or that there's an issue reinitializing the camera capture after it's been released. Here are a few steps you can take to troubleshoot the issue:
try:
# Your detection code
pass
finally:
cap.release()
cv2.destroyAllWindows()
If you continue to experience issues, please provide a minimal reproducible example directly in the GitHub issue, using code blocks to share snippets, so that I can review it within the constraints of this platform. Remember, the goal is to ensure that the camera is released after each use and properly reinitialized before the next use. Keep iterating on this process, and you should be able to find a solution. Good luck! 😊 |
I found a solution. |
Thank you for your support and help. 💯 @glenn-jocher |
@Jayashankar-K, that's fantastic news! I'm glad to hear you found a solution that works for your project. Using threading to manage the lifecycle of the detection algorithm and ensuring resources are properly released is a clever approach. Great job on troubleshooting and implementing a fix! 🎉 If you have any more questions or need further assistance as you continue to develop your project, feel free to reach out. The YOLOv5 community and the Ultralytics team are always here to help. Keep up the great work, and best of luck with your project! 😊 |
Search before asking
Question
I am working on a project which involves a condition based detection.
Which means only if a condition is met then i invoke the YOLOv5 to perform a detection from my live camera feed.
The entire code runs in an infinite loop
If the detection conditions are satisfied then the again it should check for the condition and perform detection again.
Note : I am running this on a Anaconda environment
MY ISSUE :
In the first iteration the camera module is generated and detection is performed.
After which the second iteration is unable to invoke and generating errors due to not closing of the camera module from the first iteration.
The camera module window is only closing if i press "Ctrl+C" , but all the programs running are also terminated and the conda environment returns to a static state.
Is there any way to kill only the generated camera module without stopping all the processes so that the program can run in a loop without any errors.
TRIED METHODS
I have written a code snippet to find the PID of the subprocess and tried to terminate it but it does not work.
2.Using os.kill(os.getpid(), 2)
This stopped execution of all the processes
3.Tried to use cap.close() and cv2.CloseAllWIndows()
This also does not work
I have also tried to make changes in detect.py and dataloaders.py but it was of no use.
SO IF ANYONE CAN POINT ME TO WHAT CAN BE THE POSSIBLE MISTAKE I AM DOING IT WOULD BE VERY HELPFUL.THANK YOU
Additional
I am ready to provide more information or code snippets if needed.
The text was updated successfully, but these errors were encountered: