import PyRVC as RVC
import numpy as np
import os
import cv2
from Utils.Tools import *
def App():
opt = RVC.SystemListDeviceTypeEnum.All
print("RVC Camera devices number:%d" % len(devices))
if len(devices) == 0:
print("Can not find any RVC Camera!")
return 1
print("devices size =%d" % len(devices))
if devices[0].IsFirmwareMatch() == False:
print("device firmware mismatch, Please use RVCManager to upgrade the firmware")
exit(1)
if x.IsValid() == True:
print("RVC Camera is valid!")
else:
print("RVC Camera is not valid!")
return 1
ret1 = x.Open()
if x.IsOpen() == True:
print("RVC Camera is opened!")
else:
print("Failed to open camera! Please check whether the camera is connected and make sure it is not occupied and supports X1.")
return 1
_, exp_range_min, exp_range_max = x.GetExposureTimeRange()
print("ExposureTime Range:[{}, {}]".format(exp_range_min, exp_range_max))
cap_opt = RVC.X1_CaptureOptions()
ret,cap_opt = x.LoadCaptureOptionParameters()
cap_opt.calc_normal = False
cap_opt.calc_normal_radius = 5
cap_opt.transform_to_camera = True
cap_opt.filter_range = 0
cap_opt.phase_filter_range = 0
cap_opt.projector_brightness = 240
cap_opt.exposure_time_2d = 30
cap_opt.exposure_time_3d = 30
cap_opt.gain_2d = 0
cap_opt.gain_3d = 0
cap_opt.gamma_2d = 1
cap_opt.gamma_3d = 1
use_auto_white_balance = False
if use_auto_white_balance:
white_balace_times = 10
ret2 = x.AutoWhiteBalance(white_balace_times)
if ret2:
print("Success AutoWhiteBalance")
else:
print("Failed AutoWhiteBalance")
ret3 = x.SetBandwidth(0.5)
if not ret3:
print("Failed SetBandwidth")
else:
print("Success SetBandwidth")
cap_opt.use_projector_capturing_2d_image = True
ret4 = x.Capture(cap_opt)
save_address = "Data"
TryCreateDir(save_address)
if ret4:
print("RVC Camera capture successed!")
img = x.GetImage()
width = img.GetSize().cols
height = img.GetSize().rows
print("width=%d, height=%d" % (width, height))
img_type = img.GetType()
if img_type == RVC.ImageTypeEnum.Mono8:
print("This is mono camera")
else:
print("This is color camera")
if img.SaveImage(save_address + "/image.png"):
print("Save image successed!")
else:
print("Save image failed!")
if cap_opt.calc_normal:
pm = x.GetPointMap()
normals = pm.GetNormalDataPtr()
normals = np.array(normals, copy=False).reshape(-1, 3)
pm = np.array(pm, copy=False).reshape(-1, 3)
SavePointMapWithNormal(pm, normals, height*width, "Data/test.ply")
else:
pm = np.array(x.GetPointMap(), copy=False).reshape(-1, 3)
SavePointMap(pm, height*width, "Data/test.ply")
print("Save point map successed!")
else:
print("RVC Camera capture failed!")
x.Close()
return 1
x.Close()
return 0
if __name__ == '__main__':
App()