-
Notifications
You must be signed in to change notification settings - Fork 373
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
Very simple example streaming from an opencv camera #1502
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
28bfeb5
Very simple example streaming from an opencv camera
jleibs 860c342
Warning about the memory limitations
jleibs d40e7d5
Merge branch 'main' into jleibs/canny
teh-cmc 69569dc
Merge branch 'main' into jleibs/canny
teh-cmc 743ac59
Update comments and link to known issue
jleibs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Very simple example of capturing from a live webcam. | ||
|
||
NOTE: this example currently runs forever and will eventually exhaust your | ||
system memory. It is advised you run an independent rerun viewer with a memory | ||
limit: | ||
``` | ||
rerun --memory-limit 4GB | ||
``` | ||
|
||
And then connect using: | ||
``` | ||
python examples/python/opencv_canny/main.py --connect | ||
``` | ||
|
||
""" | ||
|
||
import argparse | ||
|
||
import cv2 | ||
import rerun as rr | ||
|
||
|
||
def run_canny() -> None: | ||
# Create a new video capture | ||
cap = cv2.VideoCapture(0) | ||
|
||
while cap.isOpened(): | ||
# Read the frame | ||
ret, img = cap.read() | ||
if not ret: | ||
print("Can't receive frame (stream end?). Exiting ...") | ||
break | ||
|
||
# Get the current frame time | ||
frame_time = cap.get(cv2.CAP_PROP_POS_MSEC) | ||
rr.set_time_nanos("frame_time", int(frame_time * 1000000)) | ||
|
||
# Log the original image | ||
rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | ||
rr.log_image("image/rgb", rgb) | ||
|
||
# Convert to grayscale | ||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
rr.log_image("image/gray", gray) | ||
|
||
# Run the canny edge detector | ||
canny = cv2.Canny(gray, 50, 200) | ||
rr.log_image("image/canny", canny) | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.") | ||
parser.add_argument( | ||
"--device", type=int, default=0, help="Which camera device to use. (Passed to `cv2.VideoCapture()`)" | ||
) | ||
|
||
rr.script_add_args(parser) | ||
args = parser.parse_args() | ||
|
||
rr.script_setup(args, "opencv_canny") | ||
|
||
print(args.connect) | ||
|
||
if not args.connect: | ||
print( | ||
""" | ||
################################################################################ | ||
NOTE: this example currently runs forever and will eventually exhaust your | ||
system memory. It is advised you run an independent rerun viewer with a memory | ||
limit: | ||
``` | ||
rerun --memory-limit 4GB | ||
``` | ||
|
||
And then connect using: | ||
``` | ||
python examples/python/opencv_canny/main.py --connect | ||
``` | ||
################################################################################ | ||
""" | ||
) | ||
|
||
run_canny() | ||
|
||
rr.script_teardown(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
opencv-python | ||
rerun-sdk |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a better description