I am brand new to programming in general, and am working on a project for which I need to capture images from my webcam (possibly using OpenCV), and save the images as pgm f
Read most of the answers but none of them could satisfy the need that I have. This will act as a camera and can be used to click pictures we can change the if("c") condition to a for loop to click pictures automatically after certain interval
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 12 12:29:05 2018
@author: CodersMine
"""
import cv2
"""
Run this if you are facing invalid images issue
cap.release()
"""
cap = cv2.VideoCapture(0)#0 is internal cam : 1 is external webcam
i=0 #to save all the clicked images
while(True):
ret, frame = cap.read()
cv2.imshow("imshow",frame)
key=cv2.waitKey(30)
if key==ord('q'):
break
if key==ord('c'):
i+=1
cv2.imshow("imshow2",frame)
cv2.imwrite('C:/Users/codersmine/desktop/image'+str(i)+'.png', frame)
print("Wrote Image")
# release the capture
cap.release()
cv2.destroyAllWindows()