Skip to content

Check return value in python tutorial - #13877

Merged
opencv-pushbot merged 1 commit into
opencv:3.4from
LaurentBerger:pythonvideo
Feb 22, 2019
Merged

opencv-pushbot merged 1 commit into
opencv:3.4from
LaurentBerger:pythonvideo

Conversation

@LaurentBerger

@LaurentBerger LaurentBerger commented Feb 20, 2019 •

Copy link
Copy Markdown
Contributor

good practise in tutorial?

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error checks make sense.

if cv.waitKey(1) & 0xFF == ord('q'):
# Display the resulting frame
cv.imshow('frame',gray)
if cv.waitKey(1) & 0xFF == ord('q') or not ret:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

& 0xFF

Not needed anymore with waitKey().

# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# if frame is read correctly ret is True
if ret:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is about this?

if not ret:
    print("Can't receive frame (stream end?). Exiting...")
    break

At least we don't need to complicate condition below.

cap = cv.VideoCapture(0)

if not cap.isOpened:
print("Cannot open VideoCapture")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Cannot open camera" ?

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you 👍

@opencv-pushbot
opencv-pushbot merged commit 4ebb617 into opencv:3.4 Feb 22, 2019
@alalek alalek mentioned this pull request Feb 26, 2019
@LaurentBerger
LaurentBerger deleted the pythonvideo branch March 24, 2019 20:55
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: documentation Documentation fix or update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants