def read_register(request): global handle register = request.register rtn_val, output = ArducamSDK.Py_ArduCam_readSensorReg(handle,register) if rtn_val == 0: output = 'Register %d: %d' % (register, output) else: output = 'Invalid register' return ReadRegResponse(output)
def get_extra_label_info(self): if self.data_fields['LUM2'] == 0: self.data_fields['LUM2'] = ArducamSDK.Py_ArduCam_readSensorReg( self.handle, int(12546))[1] if self.field_index == 0 or self.data_fields['TIME'] == 0: self.data_fields['TIME'] = ArducamSDK.Py_ArduCam_readSensorReg( self.handle, int(12644))[1] if self.field_index == 1 or self.data_fields['TIME'] == 0: self.data_fields['ISO'] = ArducamSDK.Py_ArduCam_readSensorReg( self.handle, int(12586))[1] if self.field_index == 2 or self.data_fields['TIME'] == 0: self.data_fields['LUM1'] = ArducamSDK.Py_ArduCam_readSensorReg( self.handle, int(12626))[1] self.field_index = self.field_index + 1 if self.field_index < 2 else 0 return [("Time: {0} ISO: {1} LUM:{2}/{3}").format( self.data_fields['TIME'], self.data_fields['ISO'], self.data_fields['LUM1'], self.data_fields['LUM2'])]
def writeSingleSensorReg(reg_str,val_str): global handle regAddr = int(reg_str,16) val = int(val_str,16) ArducamSDK.Py_ArduCam_writeSensorReg(handle,regAddr,val) #check if value sucessfully changed: if (val == ArducamSDK.Py_ArduCam_readSensorReg(handle,regAddr)[1]): print ("SUCCESFULLY CHANGED" + ' ' + hex(regAddr) + ' ' + "TO" + ' ' + hex(val)) else: rospy.logerr ("WRITING COMMAND NOT SUCCESFULL")
def set_exposure(self, exposure): #self.camera.set_exposure_time(exposure)#us setval = round(exposure / 22.22) print(setval) ArducamSDK.Py_ArduCam_writeSensorReg(self.handle, 0x3012, setval) print(ArducamSDK.Py_ArduCam_readSensorReg(self.handle, 0x3012))
def readSingleSensorReg(reg_str): global handle regAddr = int(reg_str, 16) val = ArducamSDK.Py_ArduCam_readSensorReg(handle, regAddr)[1] print("VALUE OF" + ' ' + hex(regAddr) + ' ' + "IS" + ' ' + hex(val))
def readImage_thread(): global handle,running,Width,Height,save_flag,acfg,color_mode,save_raw global COLOR_BayerGB2BGR,COLOR_BayerRG2BGR,COLOR_BayerGR2BGR,COLOR_BayerBG2BGR count = 0 totalFrame = 0 time0 = time.time() time1 = time.time() data = {} cv2.namedWindow("ArduCam Demo",1) counter = 0 clahe = cv2.createCLAHE(clipLimit=1.0, tileGridSize=(4,4)) while running: display_time = time.time() if ArducamSDK.Py_ArduCam_availableImage(handle) > 0: rtn_val,data,rtn_cfg = ArducamSDK.Py_ArduCam_readImage(handle) datasize = rtn_cfg['u32Size'] if rtn_val != 0: print("read data fail!") continue if datasize == 0: continue image = convert_image(data,rtn_cfg,color_mode) # digits_area = image[int(image.shape[0] * 0.965):int((1 - 0) * image.shape[0]), int(image.shape[1] * 0):int((1 - 0.5) * image.shape[1]),:] #Defines height #From XXX to image.shape[1] a1 = [0, int(image.shape[0] * 0.93)] #0,896 a2 = [0, int((1 - 0) * image.shape[0])] #0,964 #Defines width #From XXX to image.shape[1] a3 = [int(image.shape[1] * 0.4), int((1 - 0) * image.shape[0])] #512,964 a4 = [int(image.shape[1] * 0.4), int(image.shape[0] * 0.93)] #512,896 digits_area = np.array([[a1, a2, a3, a4]], dtype=np.int32) #image shape: [H,W] #digits area: [W,H] # digits_area = np.array([[[512,964], [0,964], [0,896], [512,896]]], dtype=np.int32) # print(digits_area) #930 #964 #0 #640 # cv2.fillConvexPoly(image, np.array(a1, a2, a3, a4, 'int32'), 255) cv2.fillPoly( image, digits_area, (0,0,0) ) if counter == 0: filename = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + "_front_top.avi" out = cv2.VideoWriter(filename, cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), 8, (1280, 964)) # out = cv2.VideoWriter(filename, cv2.VideoWriter_fourcc('M', 'J', '2', 'C'), 8, (1280, 964)) #Lossless # out = cv2.VideoWriter(filename, cv2.VideoWriter_fourcc('H', 'F', 'Y', 'U'), 8, (1280, 964)) #Lossless reprint("Creating file " + str(filename)) cv2.putText(image, datetime.datetime.now().strftime("%Y-%m-%d: %H:%M:%S %f"), (10, image.shape[0] - 10), cv2.FONT_HERSHEY_DUPLEX, 0.8, (255, 255, 255), 1, cv2.LINE_AA) ardu = ("Time: " + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12644))[1])) + " ISO: " + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12586))[1])) + " lum: " + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12626))[1])) + "/" + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12546))[1]))) cv2.putText(image, ardu, (10, image.shape[0] - 40), cv2.FONT_HERSHEY_DUPLEX, 0.8, (255, 255, 255), 1, cv2.LINE_AA) # cv2.imshow("stream", image) # cv2.waitKey(0) out.write(image) # regAddr = int(12644) # val = hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, regAddr)[1]) # print("Integration time\t" + str(hex(12644)) + "\t" + str(hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12644))[1]))) # print("Gains\t" + str(hex(12586)) + "\t" + str(hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12586))[1]))) # print("Mean gain\t" + str(hex(12626)) + "\t" + str(hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12626))[1]))) # print("Dark current\t" + str(hex(12680)) + "\t" + str(hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12680))[1]))) # print("Frame exposure\t" + "\t" + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12460))[1]))) # logger.write(str(datetime.datetime.now().strftime("%Y-%m-%d: %H:%M:%S")) + "\t") # logger.write(str(hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12644))[1])) + "\t") # logger.write(str(hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12586))[1])) + "\t") # logger.write(str(hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12626))[1])) + "\t") # logger.write(str(hex(ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12680))[1])) + "\n") # logger.flush() cv2.resize(image,(512,384)) try: colorconversion = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) except: colorconversion = image pass for i in range(2): colorconversion = clahe.apply(colorconversion) # image = image[:,:,0] # print(image.shape) # image = cv2.cvtColor(colorconversion, cv2.COLOR_GRAY2BGR) # print(image.shape) # image = cv2.GaussianBlur(image, (3, 3), 0) # for i in range(image.shape[2]): # image[:,:,i] = colorconversion fh.post_image(colorconversion) counter += 1 if counter == 500: out.release() reprint("Sending file " + str(filename)) threading.Thread(target=fh.post_files,args=[filename]).start() counter = 0 # print("Exposure: " + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12460))[1])) + "\tAcq time: " + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12644))[1])) + "\tGain: " + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12586))[1])) + " lum: " + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12626))[1])) + "/" + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12546))[1])) + " DC: " + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12680))[1])) + "/" + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12580))[1]))) # print("Noise correction\t" + "\t" + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12500))[1]))) #print(str(regAddr) + "\t" + str(val)) #["0x3012","0x0032"] = 12306 50 #3012 (hex) = 12306 (dec) #0032 (hex) = 50 (dec) # print(str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12644))[1])) + "\t" + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12586))[1])) + "\t" + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12626))[1])) + "\t" + str((ArducamSDK.Py_ArduCam_readSensorReg(handle, int(12680))[1]))) #["0x3012","0x0032"] = 12306 50 #3012 (hex) = 12306 (dec) #0032 (hex) = 50 (dec) # if counter == 5: # cimage = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) # cv2.imwrite(os.path.join(local_dir, "frame.jpg"), cv2.resize(cimage,(512,384))) # counter = 0 # cv2.imwrite(os.path.join(local_dir, "Desktop", "images", str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S-%f") + ".jpg")), image) # counter += 1 # cv2.imshow("ArduCam Demo",image) # cv2.waitKey(10) ArducamSDK.Py_ArduCam_del(handle) #print("------------------------display time:",(time.time() - display_time)) else: time.sleep(0.001);