Access webcam camera with OpenCV Python

Access webcam camera with OpenCV Python


Access webcam camera with OpenCV python - this time admin posts How to Access webcam cameras using openCV in python.
This tutorial is the basic of OpenCV, which is accessing the camera / webcam. Camera access is an important aspect in using opencv itself. Because opencv itself is more often to access a camera / webcam. Here the admin uses a logitech camera and uses python version 3. Can also access from laptop webcam default. Just look at the source code below.


Source Code :


import cv2 #untuk memanggil komponen opencv python

videoCam = cv2.VideoCapture(0) #webcam / kamera yang digunakan
videoCam.set(cv2.CAP_PROP_FRAME_WIDTH,720) # panjang panel kamera
videoCam.set(cv2.CAP_PROP_FRAME_HEIGHT,480) # lebar panel kamera
while True:
cond, frame = videoCam.read() # membaca kondisi apabila frame sudah ada

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # cara mengkonvert gambar BGR ke Mode Gray
cv2.imshow('Original Video', frame) # menampilkan video aslinya
cv2.imshow('Gray Video', gray) # menampilkan video asli dengan efek gray

k = cv2.waitKey(1) & 0xff
if k == ord('q'): # jika menekan Q maka program akan exit.
break

videoCam.release()
cv2.destroyAllWindows()


Note :
If using 2 cameras, change the number 1 or 0 on VideoCapture (1)

Screenshot Program Result :


Posting Komentar

0 Komentar