Python Forum
Capturing a snapshot from the video
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Capturing a snapshot from the video
#1
from imutils.perspective import four_point_transform
import numpy as np
import argparse
import cv2
 
scaling_factorx = 0.8
scaling_factory = 0.8

cap = cv2.VideoCapture(0)
fgbg = cv2.createBackgroundSubtractorMOG2()
count = 0

while(1):

  ret, frame = cap.read()

  cv2.imshow('window-name', frame)
  cv2.imwrite("frame%d.jpg" %count, frame)
  count = count + 1

  frame = cv2.resize(frame, None, fx = scaling_factorx, fy = scaling_factory, interpolation = cv2.INTER_AREA)

  fgmask = fgbg.apply(frame)
  cv2.imshow('frame', fgmask)

  gray_vid = cv2.cvtColor(frame, cv2.IMREAD_GRAYSCALE)
  cv2.imshow('Original', frame)

  edged_frame = cv2.Canny(frame,100, 200)
  cv2.imshow('Edges', edged_frame)
  
  k= cv2.waitKey(30);
  if k==27:
    break

cap.release()
cv2.destroyAllWindows()
While running the code i get the error :

C:\Users\Sreeram Prakash\Desktop\Project Files>python task1.py
Traceback (most recent call last):
File "task1.py", line 17, in <module>
cv2.imshow('window-name', frame)
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:350: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Reply
#2
Your program runs well on my PC with Debian 10,
except it opens a lot of windows and writes many files.

After 10 seconds I have more than than 500 files and open windows.

Maybe you get the error because too many windows.

You should reuse the window or
sleep one second before the next step in loop.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Capturing BS4 values into DF and writing to CSV cubangt 18 1,943 Sep-05-2023, 01:57 PM
Last Post: cubangt
  capturing multiline output for number of parameters jss 3 807 Sep-01-2023, 05:42 PM
Last Post: jss
  Json filter is not capturing desired key/element mrapple2020 1 1,120 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  Capturing inputs values from internal python script limors11 11 5,183 Jun-16-2019, 05:05 PM
Last Post: DeaD_EyE
  HTTP response capturing issue miunika 1 2,021 Mar-16-2019, 01:46 PM
Last Post: Larz60+
  HTTP response capturing issue anna 2 2,497 Mar-15-2019, 03:08 PM
Last Post: Larz60+
  Capturing error from sql Grego 1 2,448 Jun-29-2018, 11:17 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020