ultralytics / ultralytics

Ultralytics YOLO11 🚀
https://docs.ultralytics.com
GNU Affero General Public License v3.0
29.47k stars 5.78k forks source link

camera changing input resolution #14214

Closed jakubkotecki6 closed 1 month ago

jakubkotecki6 commented 3 months ago

Search before asking

YOLOv8 Component

Predict

Bug

I have this problem when i try to detect objects on my thermal camera. To make it run proparely I need to change frame height, width and rate, but when i input this frame into model.predict(), it displays 1 frame then goes to miniconda3\Lib\site-packages\ultralytics\assets\ and picks up bus.jpg and zidane.jpg, then breaks down. Also when i run it on my regular webcam it does the same thing. Is there any solution to run detection on set frame height/width/rate?

https://github.com/ultralytics/ultralytics/assets/113249947/1e1a7885-7bfc-4fcb-95d5-42653cdb0b39

Environment

No response

Minimal Reproducible Example

from ultralytics import YOLO import cv2

model = YOLO("yolov10n.pt")

cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_FRAME_WIDTH, 256) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 192) cap.set(cv2.CAP_PROP_FPS, 50)

if not (cap.isOpened()): print("Could not open video device")

while True: ret, frame = cap.read()

# Perform object detection on an image
results = model.predict(frame, save=True, show=True, conf=0.15)

cv2.imshow("frame", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
    break
cap.release()

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 3 months ago

👋 Hello @jakubkotecki6, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

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.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 3 months ago

Hello @jakubkotecki6,

Thank you for reaching out and providing a detailed description of the issue you're facing. It seems like you're encountering a problem when trying to detect objects using your thermal camera with specific frame dimensions and frame rate settings.

To better assist you, could you please verify the following:

  1. Ensure you are using the latest version of the Ultralytics YOLO package. Sometimes, issues are resolved in newer releases.
  2. Provide a minimal reproducible example that consistently demonstrates the issue. This helps us diagnose the problem more effectively. You can refer to our guide on creating a minimum reproducible example.

From your description, it appears that the model is defaulting to sample images (bus.jpg and zidane.jpg) from the Ultralytics assets directory. This might happen if the input frame is not being read correctly or if there's an issue with the video capture setup.

Here are a few suggestions to troubleshoot and potentially resolve the issue:

  1. Check Video Capture Initialization: Ensure that the video capture device is correctly initialized and that frames are being read properly.

    if not cap.isOpened():
       print("Could not open video device")
       exit()
  2. Verify Frame Read: Add a check to ensure that frames are being read correctly before passing them to the model.

    while True:
       ret, frame = cap.read()
       if not ret:
           print("Failed to read frame")
           break
    
       # Perform object detection on the frame
       results = model.predict(frame, save=True, show=True, conf=0.15)
    
       cv2.imshow("frame", frame)
       if cv2.waitKey(1) & 0xFF == ord('q'):
           break
    cap.release()
  3. Set Correct Frame Dimensions: Ensure that the frame dimensions and frame rate are set correctly and supported by your camera.

    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 256)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 192)
    cap.set(cv2.CAP_PROP_FPS, 50)
  4. Debugging: Print out the frame dimensions and type to ensure they are as expected.

    print(f"Frame dimensions: {frame.shape}")
    print(f"Frame type: {type(frame)}")

If the issue persists after these checks, please provide any additional error messages or logs that might help us diagnose the problem further.

Feel free to reach out with any more details or questions. We're here to help!

github-actions[bot] commented 1 month ago

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐