Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
682e03bd
Commit
682e03bd
authored
Feb 22, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13877 from LaurentBerger:pythonvideo
parents
ca4fd1e4
4ebb6170
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
20 deletions
+28
-20
py_video_display.markdown
...torials/py_gui/py_video_display/py_video_display.markdown
+28
-20
No files found.
doc/py_tutorials/py_gui/py_video_display/py_video_display.markdown
View file @
682e03bd
...
@@ -25,23 +25,27 @@ import numpy as np
...
@@ -25,23 +25,27 @@ import numpy as np
import cv2 as cv
import cv2 as cv
cap = cv.VideoCapture(0)
cap = cv.VideoCapture(0)
if not cap.isOpened():
while(True):
print("Cannot open camera")
exit()
while True:
# Capture frame-by-frame
# Capture frame-by-frame
ret, frame = cap.read()
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
# Display the resulting frame
cv.imshow('frame',gray)
cv.imshow('frame',
gray)
if cv.waitKey(1)
& 0xFF
== ord('q'):
if cv.waitKey(1) == ord('q'):
break
break
# When everything done, release the capture
# When everything done, release the capture
cap.release()
cap.release()
cv.destroyAllWindows()
cv.destroyAllWindows()@endcode
@endcode
`cap.read()`
returns a bool (
`True`
/
`False`
). If frame is read correctly, it will be
`True`
. So you can
`cap.read()`
returns a bool (
`True`
/
`False`
). If frame is read correctly, it will be
`True`
. So you can
check end of the video by checking this return value.
check end of the video by checking this return value.
...
@@ -75,13 +79,17 @@ import cv2 as cv
...
@@ -75,13 +79,17 @@ import cv2 as cv
cap = cv.VideoCapture('vtest.avi')
cap = cv.VideoCapture('vtest.avi')
while
(cap.isOpened()
):
while
cap.isOpened(
):
ret, frame = cap.read()
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
cv.imshow('frame',gray)
cv.imshow('frame',
gray)
if cv.waitKey(1)
& 0xFF
== ord('q'):
if cv.waitKey(1) == ord('q'):
break
break
cap.release()
cap.release()
...
@@ -123,20 +131,20 @@ cap = cv.VideoCapture(0)
...
@@ -123,20 +131,20 @@ cap = cv.VideoCapture(0)
# Define the codec and create VideoWriter object
# Define the codec and create VideoWriter object
fourcc = cv.VideoWriter_fourcc(
*
'XVID')
fourcc = cv.VideoWriter_fourcc(
*
'XVID')
out = cv.VideoWriter('output.avi',
fourcc, 20.0, (640,
480))
out = cv.VideoWriter('output.avi',
fourcc, 20.0, (640,
480))
while
(cap.isOpened()
):
while
cap.isOpened(
):
ret, frame = cap.read()
ret, frame = cap.read()
if ret==True:
if not ret:
frame = cv.flip(frame,0)
print("Can't receive frame (stream end?). Exiting ...")
break
frame = cv.flip(frame, 0)
# write the flipped frame
# write the flipped frame
out.write(frame)
out.write(frame)
cv.imshow('frame',frame)
cv.imshow('frame', frame)
if cv.waitKey(1) & 0xFF == ord('q'):
if cv.waitKey(1) == ord('q'):
break
else:
break
break
# Release everything if job is finished
# Release everything if job is finished
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment