Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7a9ec9e

Browse files
Add "Video Capture" example
1 parent 6ef6dd3 commit 7a9ec9e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

‎video-capture/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Video Capture
2+
3+
An simple video capture program
4+
Copyright (c) 2024 Ercan Ersoy
5+
6+
This example shows video display from first webcam.

‎video-capture/video-capture.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# video Capture - An simple video capture program
2+
# Copyright (c) 2024 Ercan Ersoy
3+
# This file licensed under MIT License.
4+
# Write this code using ChatGPT.
5+
6+
# Imports
7+
import cv2
8+
import sys
9+
10+
# Initialize video capture
11+
capture = cv2.VideoCapture(0)
12+
13+
# Check if the webcam is opened correctly
14+
if not capture.isOpened():
15+
print("Error: Could not open webcam.", file=sys.stderr)
16+
exit()
17+
18+
# Continuously capture frames
19+
while True:
20+
# Read the frame
21+
ret, frame = capture.read()
22+
23+
# If frame is read correctly ret is True
24+
if not ret:
25+
print("Error: Failed to capture frame.", file=sys.stderr)
26+
break
27+
28+
# Display the frame
29+
cv2.imshow('Frame', frame)
30+
31+
key_code = cv2.waitKey(1)
32+
33+
# Break the loop if ESC is pressed
34+
if cv2.getWindowProperty("Frame", cv2.WND_PROP_VISIBLE) < 1:
35+
break
36+
37+
# Release the video capture object
38+
capture.release()
39+
40+
# Close windows
41+
cv2.destroyAllWindows()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /