mirror of
https://github.com/opencv/opencv.git
synced 2025-07-31 18:07:08 +08:00
Added camera open check
This commit is contained in:
parent
0d7d045a3b
commit
1d420dc9c0
@ -171,6 +171,11 @@ int main(int argc, char** argv) {
|
|||||||
else
|
else
|
||||||
cap.open(0);
|
cap.open(0);
|
||||||
|
|
||||||
|
if (!cap.isOpened()) {
|
||||||
|
cerr << "Error: Video could not be opened." << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
namedWindow("Input", WINDOW_AUTOSIZE);
|
namedWindow("Input", WINDOW_AUTOSIZE);
|
||||||
namedWindow("Output", WINDOW_AUTOSIZE);
|
namedWindow("Output", WINDOW_AUTOSIZE);
|
||||||
moveWindow("Output", 200, 0);
|
moveWindow("Output", 200, 0);
|
||||||
|
@ -229,6 +229,12 @@ int main(int argc, char **argv)
|
|||||||
cap.open(findFile(parser.get<String>("input")));
|
cap.open(findFile(parser.get<String>("input")));
|
||||||
else
|
else
|
||||||
cap.open(parser.get<int>("device"));
|
cap.open(parser.get<int>("device"));
|
||||||
|
|
||||||
|
if (!cap.isOpened()) {
|
||||||
|
cerr << "Error: Video could not be opened." << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
//! [Open a video file or an image file or a camera stream]
|
//! [Open a video file or an image file or a camera stream]
|
||||||
// Process frames.
|
// Process frames.
|
||||||
Mat frame, blob;
|
Mat frame, blob;
|
||||||
|
@ -110,6 +110,10 @@ def main(func_args=None):
|
|||||||
cv.namedWindow(winName, cv.WINDOW_AUTOSIZE)
|
cv.namedWindow(winName, cv.WINDOW_AUTOSIZE)
|
||||||
|
|
||||||
cap = cv.VideoCapture(cv.samples.findFile(args.input) if args.input else 0)
|
cap = cv.VideoCapture(cv.samples.findFile(args.input) if args.input else 0)
|
||||||
|
if not cap.isOpened():
|
||||||
|
print("Failed to open the input video")
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
legend = None
|
legend = None
|
||||||
while cv.waitKey(1) < 0:
|
while cv.waitKey(1) < 0:
|
||||||
hasFrame, frame = cap.read()
|
hasFrame, frame = cap.read()
|
||||||
|
Loading…
Reference in New Issue
Block a user