Community
cancel
Showing results for 
Search instead for 
Did you mean: 
MTava2
Beginner
2,627 Views

USB CAMERA WITH OPENCV

how can i see from a usb camera with opencv?

My usb camera is /dev/video14

and I would like to see from the usb camera with the following code:

import numpy as np

import cv2

cap = cv2.VideoCapture(0)

while(True):

# Capture frame-by-frame

ret, frame = cap.read()

# Our operations on the frame come here

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Display the resulting frame

cv2.imshow('frame',gray)

if cv2.waitKey(1) & 0xFF == ord('q'):

break

# When everything done, release the capture

cap.release()

cv2.destroyAllWindows()

I know that with the r200 this code is used

import logging

logging.basicConfig(level=logging.INFO)

import time

import numpy as np

import cv2

import pyrealsense as pyrs

from pyrealsense.constants import rs_option

with pyrs.Service() as serv:

with serv.Device() as dev:

dev.apply_ivcam_preset(0)

try: # set custom gain/exposure values to obtain good depth image

custom_options = [(rs_option.RS_OPTION_R200_LR_EXPOSURE, 30.0),

(rs_option.RS_OPTION_R200_LR_GAIN, 100.0)]

dev.set_device_options(*zip(*custom_options))

except pyrs.RealsenseError:

pass # options are not available on all devices

cnt = 0

last = time.time()

smoothing = 0.9

fps_smooth = 30

while True:

cnt += 1

if (cnt % 10) == 0:

now = time.time()

dt = now - last

fps = 10/dt

fps_smooth = (fps_smooth * smoothing) + (fps * (1.0-smoothing))

last = now

dev.wait_for_frames()

c = dev.color

c = cv2.cvtColor(c, cv2.COLOR_RGB2BGR)

d = dev.depth * dev.depth_scale * 1000

d = cv2.applyColorMap(d.astype(np.uint8), cv2.COLORMAP_RAINBOW)

cd = np.concatenate((c, d), axis=1)

cv2.putText(cd, str(fps_smooth)[:4], (0, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 0))

cv2.imshow('', cd)

if cv2.waitKey(1) & 0xFF == ord('q'):

break

but I throw this error when I run the code, I guess the error comes out because it is not the r200, how could my camera usb work, by the way I've already tried it and if it captures photos

Tags (1)
0 Kudos
5 Replies
idata
Community Manager
281 Views

Hi MarioTavarez,

 

 

Thank you for your interest in the Intel Aero drone.

 

Please let me look into it and I will get back to you later.

 

 

Regards,

 

Alexandra
idata
Community Manager
281 Views

Hello MarioTavarez,

 

 

As stated in the package description, MacOS and Linux packages do not support video related functionality (not compiled with FFmpeg). You will have to compile OpenCV manually.

 

Let me know if you have further questions.

 

 

Regards,

 

Alexandra
MTava2
Beginner
281 Views

I have already compiled opencv before including opencvcontrib that contains its extra modules that I use and I need to use in the intel aero but I mark that error when I run that little script on the camera, I do not know if I take it as the main camera, I just need to Call usb camera through an opencv videocapture function but it does not work

idata
Community Manager
281 Views

Hi MarioTavarez,

 

 

I am still investigating your issue.

 

Could you tell me what camera model do you have?

 

 

Regards,

 

Alexandra
MTava2
Beginner
281 Views

I found the solution to the problem, in the videocapture () function you have to pass the path of the device in this case I want to use the 14 ie the usb camera, therefore I put this code in case you are interested in documenting

import numpy as np

import cv2

cap = cv2.VideoCapture('/dev/video14') # In this part I put the route camera

while(True):

# Capture frame-by-frame

ret, frame = cap.read()

# Our operations on the frame come here

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Display the resulting frame

cv2.imshow('frame',gray)

if cv2.waitKey(1) & 0xFF == ord('q'):

break

# When everything done, release the capture

cap.release()

cv2.destroyAllWindows()

Reply