-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
71 lines (57 loc) · 1.75 KB
/
test.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import videoInput as vi
import numpy as np
print vi.VERSION
print "LOADED VIDEOINPUT LIB"
vin = vi.videoInput_getInstance()
assert isinstance(vin, vi.videoInput)
devices = vi.DeviceList()
vin.getListOfDevices(devices)
for d in devices:
assert isinstance(d, vi.Device)
print d.friendlyName, d.symbolicName
dev = d
dev = devices[1]
assert isinstance(dev, vi.Device)
print "LOADED CAPTURE DEVICES"
deviceSettings = vi.DeviceSettings()
deviceSettings.symbolicLink = dev.symbolicName
deviceSettings.indexStream = 0
deviceSettings.indexMediaType = 195
captureSettings = vi.CaptureSettings()
captureSettings.readMode = vi.ReadMode.SYNC
captureSettings.videoFormat = vi.CaptureVideoFormat.RGB24
stream = dev.listStream[0]
assert isinstance(stream, vi.Stream)
mediaType = stream.listMediaType[195]
for mt in stream.listMediaType:
print mt.width, mt.height, mt.MF_MT_FRAME_RATE
assert isinstance(mediaType, vi.MediaType)
frame = np.zeros((mediaType.height, mediaType.width,3), dtype=np.uint8)
frame.shape = (mediaType.height* mediaType.width*3)
res = vin.setupDevice(deviceSettings, captureSettings)
if res != 0:
exit
print "SUCCESSFULLY SETUP DEVICE"
readSetting = vi.ReadSetting()
readSetting.symbolicLink = deviceSettings.symbolicLink
readSetting.setNumpyArray(frame)
frame.shape = (mediaType.height, mediaType.width,-1)
import cv2
from time import time
ts = time()
while 1:
now =time()
dt = ts-now
ts = now
try:
print 1/dt
except:
pass
res = vin.readPixels(readSetting)
cv2.imshow('image',frame[:,:,:])
if cv2.waitKey(1) == 27:
break
res = vin.closeDevice(deviceSettings)
if res != 0:
exit
print "SUCCESSFULLY CLOSED DEVICE"