This repository has been archived by the owner on Nov 26, 2022. It is now read-only.
forked from vinihernech/camera-calibration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture_image_mod.py
70 lines (65 loc) · 2.3 KB
/
capture_image_mod.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
from is_wire.core import Channel,Subscription,Message
from is_msgs.image_pb2 import Image
import numpy as np
import cv2
import json
import time
import glob
import os
camera_id = 2
h = 720
w = 1280
arucos = 12
def to_np(input_image):
if isinstance(input_image, np.ndarray):
return input_image
elif isinstance(input_image, Image):
buffer = np.frombuffer(input_image.data, dtype=np.uint8)
output_image = cv2.imdecode(buffer, flags=cv2.IMREAD_COLOR)
else:
output_image = np.array([], dtype=np.uint8)
return output_image
if __name__ == '__main__':
#alterar o ID da camera e o diretório
print('---RUNNING EXAMPLE DEMO OF THE CAMERA CLIENT---')
#fourcc = cv2.VideoWriter_fourcc(*'MJPG')
broker_uri = "amqp://10.10.3.188:30000"
channel = Channel(broker_uri)
subscription = Subscription(channel=channel,name="Intelbras_Camera")
subscription.subscribe(topic='CameraGateway.{}.Frame'.format(camera_id))
ARUCO_DICT = cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50)
window = 'Intelbras Camera'
cv2.namedWindow("camera", cv2.WINDOW_NORMAL)
cv2.resizeWindow("camera", h, w)
n=0
t=0
img_array = []
while True:
msg = channel.consume()
im = msg.unpack(Image)
frame = to_np(im)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
corners, ids, _ = cv2.aruco.detectMarkers( image=gray,dictionary=ARUCO_DICT)
try:
if len(ids) == arucos and t == 40:
n += 1
img_array.append(frame)
cv2.imwrite(f'./calibration_img/cam{camera_id}/intrinsic/img{n}.png',frame)
os.system('spd-say "captured"')
t=0
except:
pass
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.imshow("camera", frame)
t = t+1
if t > 40:
t=0
# for filename in glob.glob(f'./calibration_img/cam{camera_id}/intrinsic/img*.png'):
# img = cv2.imread(filename)
# height, width, layers = img.shape
# size = (width,height)
# img_array.append(img)
# out = cv2.VideoWriter(f'./calibration_img/cam{camera_id}/intrinsic/project2.avi',cv2.VideoWriter_fourcc(*'DIVX'), 20, size)
# for i in range(len(img_array)):
# out.write(img_array[i])