'webcam'에 해당되는 글 2건

  1. 2018.01.25 OpenCV와 Python을 이용한 Webcam Capture
  2. 2018.01.25 Webcam in Ubuntu

https://www.learnopencv.com/read-write-and-display-a-video-using-opencv-cpp-python/



위 링크에서 내가 필요한 부분만 찾아서 아래에 기술했는데,

우분투 콘솔서버를 사용중이라서

아래 코드중에서

     cv2.imshow('frame',frame)

부분은 주석처리해서 사용했다.

이렇게하면 웹캠을 실시간 캡쳐해서 avi 로 만들기만하는 코드가된다.



Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import cv2
import numpy as np
 
# Create a VideoCapture object
cap = cv2.VideoCapture(0)
 
# Check if camera opened successfully
if (cap.isOpened() == False):
  print("Unable to read camera feed")
 
# Default resolutions of the frame are obtained.The default resolutions are system dependent.
# We convert the resolutions from float to integer.
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
 
# Define the codec and create VideoWriter object.The output is stored in 'outpy.avi' file.
out = cv2.VideoWriter('outpy.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame_width,frame_height))
 
while(True):
  ret, frame = cap.read()
 
  if ret == True:
     
    # Write the frame into the file 'output.avi'
    out.write(frame)
 
    # Display the resulting frame   
    cv2.imshow('frame',frame)
 
    # Press Q on keyboard to stop recording
    if cv2.waitKey(1) & 0xFF == ord('q'):
      break
 
  # Break the loop
  else:
    break 
 
# When everything done, release the video capture and video write objects
cap.release()
out.release()
 
# Closes all the frames
cv2.destroyAllWindows()

캠쳐를 실패했을때

웹캠 디바이스를 확인하고 사용가능 모드로 바꿔줘야한다.

ls -alF /dev/video*


결과


crw-r----- 1 root video 81, 0  1월 25 01:15 /dev/video0


뭐 이런경우라면,

root 사용자나 video 사용자만 웹캠을 사용할 수 있다는 말이된다.


sudo chmod 666 /dev/video0


이런식으로 해서 다른 사용자에게 권한을 부여해준다.


Posted by stekilove
,

https://help.ubuntu.com/community/Webcam


위 링크는 우분투에서 웹캠 사용을 어떻게 할지 잘 알려주는 문서이다.

난 우분투에서 콘솔 서버를 사용중이고 

실시간 비데오 스트림을 하는 것이 최종 목표이다.


차례

  1. Choosing a Webcam
  2. Testing Your Webcam Using Cheese
  3. Webcam Software
    1. Configuring Webcam Software
    2. VLC
    3. FFmpeg
    4. MPlayer
    5. MEncoder
    6. Skype
    7. streamer
  4. Identifying Your Webcam
  5. Driver installation
  6. See Also
  7. External Links


Posted by stekilove
,