Skip to content
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

[Question]: how to stream frames from opencv capture already in use? #389

Closed
4 tasks done
netpbcl opened this issue Mar 14, 2024 · 2 comments
Closed
4 tasks done
Labels
ANSWERED IN DOCS 📖 Already answered in our Docs! QUESTION ❓ User asked about the working/usage of VidGear APIs. SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! WAITING FOR RESPONSE ⏳ Waiting for the user response.

Comments

@netpbcl
Copy link

netpbcl commented Mar 14, 2024

Issue guidelines

Issue Checklist

  • I have searched open or closed issues for my problem and found nothing related or helpful.
  • I have read the Documentation and found nothing related to my problem.
  • I have gone through the Bonus Examples and FAQs and found nothing related or helpful.

Describe your Question

I, Hello, I need to know how to transmit the opencv frames that are already being used. I have the following code: I want to transmit the image that is being generated in "im1", with webgear_rtc (I suppose). Note: I am a novice programmer.

Thank you

Terminal log output(Optional)

No response

Python Code(Optional)

from ultralytics import YOLO
from ultralytics.solutions import object_counter
import cv2

model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture("path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

# Define line points
line_points = [(20, 400), (1080, 400)]

# Video writer
video_writer = cv2.VideoWriter("object_counting_output.avi",
                       cv2.VideoWriter_fourcc(*'mp4v'),
                       fps,
                       (w, h))

# Init Object Counter
counter = object_counter.ObjectCounter()
counter.set_args(view_img=True,
                 reg_pts=line_points,
                 classes_names=model.names,
                 draw_tracks=True)

while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    tracks = model.track(im0, persist=True, show=False)

    im1 = counter.start_counting(im0, tracks)
    video_writer.write(im0)

cap.release()
video_writer.release()
cv2.destroyAllWindows()

VidGear Version

0.3.0

Python version

3.11

Operating System version

windows 11

Any other Relevant Information?

No response

@netpbcl netpbcl added the QUESTION ❓ User asked about the working/usage of VidGear APIs. label Mar 14, 2024
Copy link

welcome bot commented Mar 14, 2024

Thanks for opening this issue, a maintainer will get back to you shortly!

In the meantime:

  • Read our Issue Guidelines, and update your issue accordingly. Please note that your issue will be fixed much faster if you spend about half an hour preparing it, including the exact reproduction steps and a demo.
  • Go comprehensively through our dedicated FAQ & Troubleshooting section.
  • For any quick questions and typos, please refrain from opening an issue, as you can reach us on Gitter community channel.

@abhiTronix
Copy link
Owner

I, Hello, I need to know how to transmit the opencv frames that are already being used. I have the following code: I want to transmit the image that is being generated in "im1", with webgear_rtc (I suppose). Note: I am a novice programmer.

Just follow this example: https://abhitronix.github.io/vidgear/v0.3.2-stable/gears/webgear_rtc/advanced/#using-webgear_rtc-with-a-custom-sourceopencv

@abhiTronix abhiTronix added SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! WAITING FOR RESPONSE ⏳ Waiting for the user response. ANSWERED IN DOCS 📖 Already answered in our Docs! labels Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ANSWERED IN DOCS 📖 Already answered in our Docs! QUESTION ❓ User asked about the working/usage of VidGear APIs. SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! WAITING FOR RESPONSE ⏳ Waiting for the user response.
Projects
None yet
Development

No branches or pull requests

2 participants