Merge pull request #26485 from gursimarsingh:fixed_edge_detection_and_segmentation_sample

Added cap.isOpened() check to edge detection and segmentation sample
pull/26403/merge
Alexander Smorkalov 1 week ago committed by GitHub
commit db1aa3c8a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      samples/dnn/edge_detection.cpp
  2. 6
      samples/dnn/segmentation.cpp
  3. 4
      samples/dnn/segmentation.py

@ -171,6 +171,11 @@ int main(int argc, char** argv) {
else
cap.open(0);
if (!cap.isOpened()) {
cerr << "Error: Video could not be opened." << endl;
return -1;
}
namedWindow("Input", WINDOW_AUTOSIZE);
namedWindow("Output", WINDOW_AUTOSIZE);
moveWindow("Output", 200, 0);

@ -229,6 +229,12 @@ int main(int argc, char **argv)
cap.open(findFile(parser.get<String>("input")));
else
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]
// Process frames.
Mat frame, blob;

@ -110,6 +110,10 @@ def main(func_args=None):
cv.namedWindow(winName, cv.WINDOW_AUTOSIZE)
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
while cv.waitKey(1) < 0:
hasFrame, frame = cap.read()

Loading…
Cancel
Save