def run(self): while self.gui.stop2_state == 1: self.image = np.array(HKIPcamera.getframe()) show = cv2.resize(self.image, DIM2) show = cv2.cvtColor(show, cv2.COLOR_BGR2RGB) if self.gui.Cal2_state == 1: map1, map2 = cv2.fisheye.initUndistortRectifyMap( K2, D2, np.eye(3), K2, DIM2, cv2.CV_16SC2) show = cv2.remap(show, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) time.sleep(0.005) else: time.sleep(0.015) showImage = QtGui.QImage(show.data, show.shape[1], show.shape[0], QtGui.QImage.Format_RGB888) self.gui.videolabel.setPixmap(QtGui.QPixmap.fromImage(showImage)) if self.gui.framesaveflag == 1: save_path = mkdir(self.gui.filepath.text( )) + "\\" + datetime.datetime.now().strftime('%m%d-%H%M%S') cv2.imwrite(save_path + ".jpg", self.image) map1, map2 = cv2.fisheye.initUndistortRectifyMap( K, D, np.eye(3), K, DIM, cv2.CV_16SC2) undistorted_img = cv2.remap(self.image, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) cv2.imwrite(save_path + "d.jpg", undistorted_img) self.gui.framesaveflag = 0 HKIPcamera.release() self.gui.stop2.setIcon(qtawesome.icon('fa.forward', color='white'))
def main(camera_id): ip = str('192.168.0.6') name = str('admin') pw = str('a1234567') camera = HKCamera(ip, name, pw) threadPubMsg_shelfID_7 = pubmsg.MsgPublishClass(cameraID=camera_id, shelfID=7) threadPubMsg_shelfID_7.setDaemon(True) threadPubMsg_shelfID_7.start() threadPubMsg_dict = {'shelfID_7': threadPubMsg_shelfID_7} model = loadDataset() cfg = Darknet('cfg/yolov3.cfg') cfg.load_weights('yolov3.weights') cfg.cuda() # global frame_number frame_number2 = [0] flag = [0] bridge = CvBridge() dic_change = {} huojia1_id = 7 while not rospy.is_shutdown(): frame_origin = camera.getFrame() frame_origin = np.array(frame_origin) frame_origin = cv2.resize(frame_origin, None, fx=0.75, fy=0.75, interpolation=cv2.INTER_AREA) frame_trans = copy.deepcopy(frame_origin) res, camera_id = callback( (None, cfg, model, frame_number2, bridge, camera_id, flag, frame_origin)) if res == []: threadPubMsg = threadPubMsg_dict['shelfID_' + str(huojia1_id)] threadPubMsg.set_commodity_recognition_trigger_with_image(camera_id=camera_id, person_id=-1, shelf_id=-1, flag=0, flag1=0, flag2=0, flag_list=[], frame=frame_trans) continue dic = xuanze_original(res, frame_origin, model, cfg, camera_id, dic_change, huojia1_id) if compare_dic(dic, dic_change) == False: pass else: dic = xuanze(res, frame_origin, model, cfg, threadPubMsg_dict, camera_id, dic, dic_change, huojia1_id, frame_trans) print("**********************") print("dic_change shelf7: {}".format(dic)) print("") dic_change = dic HKIPcamera.release()
def PicRec(loginfo, filepath, stop2_state, Cal2_state, framesaveflag, PicQueue): loginfoready = str(loginfo).split(':') ip = loginfoready[2] # 摄像头IP地址,要和本机IP在同一局域网 name = loginfoready[0] # 管理员用户名 pw = loginfor[1] # 管理员密码 if HKIPcamera.init(ip, name, pw) < 0: with stop2_state.get_lock(): stop2_state.value = 0 # self.gui.stop2.setIcon(qtawesome.icon('fa.forward', color='white')) win32api.MessageBox(0, "No Camera Found", "Error") else: with stop2_state.get_lock(): stop2_state.value = 1 # self.gui.stop2.setIcon(qtawesome.icon('fa.stop', color='white')) while stop2_state.value == 1: image = np.array(HKIPcamera.getframe()) show = cv2.resize(image, DIM2) show = cv2.cvtColor(show, cv2.COLOR_BGR2RGB) if Cal2_state.value == 1: map1, map2 = cv2.fisheye.initUndistortRectifyMap( K2, D2, np.eye(3), K2, DIM2, cv2.CV_16SC2) show = cv2.remap(show, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) time.sleep(0.005) else: time.sleep(0.015) showImage = QtGui.QImage(show, show.shape[1], show.shape[0], QtGui.QImage.Format_RGB888) if (PicQueue.qsize() != 0): PicQueue.put(QtGui.QPixmap.fromImage(showImage)) if framesaveflag.value == 1: save_path = mkdir(filepath) + "\\" + datetime.datetime.now( ).strftime('%m%d-%H%M%S') cv2.imwrite(save_path + ".jpg", image) map1, map2 = cv2.fisheye.initUndistortRectifyMap( K, D, np.eye(3), K, DIM, cv2.CV_16SC2) undistorted_img = cv2.remap(image, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) cv2.imwrite(save_path + "d.jpg", undistorted_img) with framesaveflag.get_clock(): framesaveflag.value = 0 HKIPcamera.release()
def main(camera_id): # ip = str('192.168.0.12') name = str('admin') pw = str('a1234567') camera = HKCamera(ip, name, pw) threadPubMsg = pubmsg.MsgPublishClass(camera_id) threadPubMsg.setDaemon(True) threadPubMsg.start() model = loadDataset() cfg = Darknet('cfg/yolov3.cfg') cfg.load_weights('yolov3.weights') cfg.cuda() print "main cfg: ", cfg.width, cfg.height # global frame_number frame_number2 = [0] # flag = [0] bridge = CvBridge() while not rospy.is_shutdown(): frame = camera.getFrame() frame = np.array(frame) frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA) frame = cv2.resize(frame, None, fx=1.5, fy=1.5, interpolation=cv2.INTER_AREA) # cv2.imshow('4', frame) # cv2.waitKey(1) callback((threadPubMsg, cfg, model, frame_number2, bridge, camera_id, frame)) HKIPcamera.release()
def HKI_base64(ip, name, pw): HKIPcamera.init(ip, name, pw) print('here0') # HKIPcamera.getfram() while 1: print(ip, name, pw, '#'*5) # frame = HKIPcamera.getframe() frame = HKIPcamera.getframe() # time.sleep(3) print('1.1', type(frame)) img = np.array(frame) # print('img=', img) # cv2.imshow('Camera', img) img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) cv2.namedWindow('Camera', flags=cv2.WINDOW_NORMAL) cv2.imshow('Camera', img) cv2.waitKey(1) # print('here') # time.sleep(0.1) HKIPcamera.release()
def call_camera(common, camera_id): ip = '192.168.0.' + str(camera_id) name = str('admin') pw = str('a1234567') camera = HKCamera(ip, name, pw) model = common.loadDataset() while not rospy.is_shutdown(): frame_origin = camera.getFrame() frame_origin = np.array(frame_origin) cv2.imshow('Cam2', frame_origin) frame_origin = cv2.resize(frame_origin, None, fx=0.75, fy=0.75, interpolation=cv2.INTER_AREA) frame_trans = copy.deepcopy(frame_origin) print("*******") wh_ratio = frame_origin.shape[1] / frame_origin.shape[0] #cv2.imshow('Cam2', cv2.resize(frame_origin, (int(512 * wh_ratio), 512))) # cfg = Darknet('cfg/yolov3.cfg') # cfg.load_weights('yolov3.weights') # cfg.cuda() # # global frame_number # frame_number2 = [0] # flag = [0] # bridge = CvBridge() # # res, camera_id = common.callback( # (None, cfg, model, frame_number2, bridge, camera_id, flag, frame_origin)) HKIPcamera.release()
def __init__(self, guii): threading.Thread.__init__(self) self.gui = guii # self.cap = cv2.VideoCapture(self.gui.rtsp.text()) self.time = 0 loginfo = str(self.gui.rtsp.text()).split(':') ip = loginfo[2] # 摄像头IP地址,要和本机IP在同一局域网 name = loginfo[0] # 管理员用户名 pw = loginfo[1] # 管理员密码 if HKIPcamera.init(ip, name, pw) < 0: self.gui.stop2_state = 0 self.gui.stop2.setIcon(qtawesome.icon('fa.forward', color='white')) win32api.MessageBox(0, "No Camera Found", "Error") else: self.gui.stop2.setIcon(qtawesome.icon('fa.stop', color='white'))
def __init__(self, ip, name, pw, port=8000, channel=1, streamtype=0, link_mode=1, queueSize=10, device_id=0): self.ip = ip self.name = name self.pw = pw self.port = port self.channel = channel self.streamtype = streamtype self.link_mode = link_mode self.device_id = device_id self.hkipc = HKIPcamera.HKIPCamera() self.mp = False if self.mp: self.Q = mp.Queue(maxsize=queueSize) else: self.Q = Queue(maxsize=queueSize)
def main(camera_id, shelf_id): rospy.init_node('MultiProcessingNode', anonymous=True) ip = '192.168.0.' + str(camera_id) name = str('admin') pw = str('a1234567') camera = HKCamera(ip, name, pw) threadPubMsg_shelfID_1 = pubmsg.MsgPublishClass(cameraID=camera_id, shelfID=shelf_id[0]) threadPubMsg_shelfID_1.setDaemon(True) threadPubMsg_shelfID_1.start() shelf1 = 'shelfID_' + str(shelf_id[0]) threadPubMsg_dict = {shelf1: threadPubMsg_shelfID_1} model = loadDataset() cfg = Darknet('cfg/yolov3.cfg') cfg.load_weights('yolov3.weights') cfg.cuda() # global frame_number frame_number2 = [0] flag = [0] bridge = CvBridge() dic_change = {} pre_res = {} huojia1_id = shelf_id[0] print("huojia1_id: {}".format(huojia1_id)) tmp = 0 while not rospy.is_shutdown(): frame_origin = camera.getFrame() frame_origin = np.array(frame_origin) frame_origin = cv2.resize(frame_origin, None, fx=0.75, fy=0.75, interpolation=cv2.INTER_AREA) frame_trans = copy.deepcopy(frame_origin) # draw the shangping area # left_x, top_y, right_m, bottom_n = shangpin_area(huojia1_id) # cv2.rectangle(frame_origin, (left_x, top_y), (right_m, bottom_n), (0, 255, 0), 2) res, camera_id, dict_res = callback( (None, cfg, model, frame_number2, bridge, camera_id, flag, frame_origin, huojia1_id, pre_res)) if res == []: if tmp > 30: threadPubMsg = threadPubMsg_dict['shelfID_' + str(huojia1_id)] threadPubMsg.set_commodity_recognition_trigger_with_image( camera_id=camera_id, person_id=-1, shelf_id=huojia1_id, flag=0, flag1=0, flag2=0, flag_list=[], frame=None) tmp = 0 else: tmp += 1 continue else: tmp = 0 dic = xuanze_original(res, frame_origin, model, cfg, camera_id, dic_change, huojia1_id, pre_res) if compare_dic(dic, dic_change) == False: pass pre_res = dict_res else: dic = xuanze(res, frame_origin, model, cfg, threadPubMsg_dict, camera_id, dic, dic_change, huojia1_id, frame_trans, pre_res) pre_res = {} #print("**********************") #print("dic_change_shelf_{}: {}".format(shelf_id[0], dic)) #print("") dic_change = dic HKIPcamera.release()
def getFrame(self): frame = HKIPcamera.getframe() return frame
def __init__(self, ip, name, pw): self._ip = ip self._name = name self._pw = pw HKIPcamera.init(self._ip, self._name, self._pw)
def getFrame(self): # HKIPcamera.init(self._ip, self._name, self._pw) frame = HKIPcamera.getframe() return frame
else: print("ASFInitEngine sucess: {}".format(res)) ip = str('192.168.33.214') # 摄像头IP地址,要和本机IP在同一局域网 name = str('admin') # 管理员用户名 pw = str('kunjuee.com') # 管理员密码 # RGB图像 img1 = cv2.imread("asserts/1.jpg") img2 = cv2.imread("asserts/2.jpg") # IR活体检测图像 img3 = cv2.imread("asserts/3.jpg") img4 = cv2.imread("asserts/4.jpg") img5 = cv2.imread("asserts/5.jpg") img6 = cv2.imread("asserts/6.jpg") img7 = cv2.imread("asserts/7.jpg") HKIPcamera.init(ip, name, pw) while True: fram = HKIPcamera.getframe() cv2.namedWindow("frame", 0) # 0可调大小,注意:窗口名必须imshow里面的一窗口名一直 cv2.resizeWindow("frame", 600, 400) # y, u, v = bgr2yuv(np.array(fram)) # # res =yuv2bgr( y, u, v) cv2.imshow('frame', np.array(fram)) # if cv2.waitKey(24) & 0xff == 27: # break # # HKIPcamera.release()
def main(camera_id): ip = str('192.168.0.2') name = str('admin') pw = str('a1234567') camera = HKCamera(ip, name, pw) threadPubMsg_shelfID_1 = pubmsg.MsgPublishClass(cameraID=camera_id, shelfID=1) threadPubMsg_shelfID_1.setDaemon(True) threadPubMsg_shelfID_1.start() threadPubMsg_shelfID_2 = pubmsg.MsgPublishClass(cameraID=camera_id, shelfID=2) threadPubMsg_shelfID_2.setDaemon(True) threadPubMsg_shelfID_2.start() threadPubMsg_dict = { 'shelfID_1': threadPubMsg_shelfID_1, 'shelfID_2': threadPubMsg_shelfID_2 } model = loadDataset() cfg = Darknet('cfg/yolov3.cfg') cfg.load_weights('yolov3.weights') cfg.cuda() # global frame_number frame_number2 = [0] flag = [0] bridge = CvBridge() dic_change = {} dic_change_huojia2 = {} huojia1_id = 1 huojia2_id = 2 while not rospy.is_shutdown(): frame_origin = camera.getFrame() frame_origin = np.array(frame_origin) frame_origin = cv2.resize(frame_origin, None, fx=0.75, fy=0.75, interpolation=cv2.INTER_AREA) frame_trans = copy.deepcopy(frame_origin) # # draw the shangping area # left_x, top_y, right_m, bottom_n = shangpin_area() # cv2.rectangle(frame_origin, (left_x, top_y), (right_m, bottom_n), (0, 255, 0), 2) # # left_x_2, top_y_2, right_m_2, bottom_n_2 = shangpin_area_huojia2() # cv2.rectangle(frame_origin, (left_x_2, top_y_2), (right_m_2, bottom_n_2), (255, 0, 0), 2) res, camera_id = callback((None, cfg, model, frame_number2, bridge, camera_id, flag, frame_origin)) if res == []: threadPubMsg = threadPubMsg_dict['shelfID_' + str(huojia1_id)] threadPubMsg.set_commodity_recognition_trigger_with_image( camera_id=camera_id, person_id=-1, shelf_id=-1, flag=0, flag1=0, flag2=0, flag_list=[], frame=frame_trans) threadPubMsg = threadPubMsg_dict['shelfID_' + str(huojia2_id)] threadPubMsg.set_commodity_recognition_trigger_with_image( camera_id=camera_id, person_id=-1, shelf_id=-1, flag=0, flag1=0, flag2=0, flag_list=[], frame=frame_trans) continue dic, dic_huojia2 = xuanze_original(res, frame_origin, model, cfg, camera_id, dic_change, dic_change_huojia2, huojia1_id, huojia2_id) if compare_dic(dic, dic_change) == False and compare_dic( dic_huojia2, dic_change_huojia2) == False: pass else: dic, dic_huojia2 = xuanze(res, frame_origin, model, cfg, threadPubMsg_dict, camera_id, dic, dic_change, dic_huojia2, dic_change_huojia2, huojia1_id, huojia2_id, frame_trans) print("**********************") print("dic_change shelf1: {}".format(dic)) print("dic_change_shelf2: {}".format(dic_huojia2)) print("") dic_change = dic dic_change_huojia2 = dic_huojia2 HKIPcamera.release()
def main(camera_id): ip = str('192.168.0.12') name = str('admin') pw = str('a1234567') camera = HKCamera(ip, name, pw) threadPubMsg = pubmsg.MsgPublishClass(cameraID=camera_id) threadPubMsg.setDaemon(True) threadPubMsg.start() model = loadDataset() cfg = Darknet('cfg/yolov3.cfg') cfg.load_weights('yolov3.weights') cfg.cuda() # global frame_number frame_number2 = [0] flag = [0] bridge = CvBridge() threadPubMsg.set_commodity_recognition_trigger(camera_id=12, person_id=0, flag=1, flag1=0, flag2=0) dic_change = {} dic_change_huojia2 = {} huojia1_id = 1 huojia2_id = 2 while not rospy.is_shutdown(): frame = camera.getFrame() frame = np.array(frame) frame = cv2.resize(frame, None, fx=0.75, fy=0.75, interpolation=cv2.INTER_AREA) res, threadPubMsg, camera_id = callback( (threadPubMsg, cfg, model, frame_number2, bridge, camera_id, flag, frame)) # if no person in the scene, send(0, 0, 0) #print("res: {}".format(res)) if res == []: #print("alallalallal") threadPubMsg.set_commodity_recognition_trigger_with_image( camera_id=camera_id, person_id=-1, shelf_id=-1, flag=0, flag1=0, flag2=0, flag_list=[], frame=None) continue dic, dic_huojia2 = xuanze_original(res, frame, model, cfg, threadPubMsg, camera_id, dic_change, dic_change_huojia2, huojia1_id, huojia2_id) #print("11111122222222") #print('dic',dic) #print('dic_change',dic_change) #print(compare_dic(dic, dic_change)) if compare_dic(dic, dic_change) == False and compare_dic( dic_huojia2, dic_change_huojia2) == False: pass else: #print("track") #print("22222233333333") dic, dic_huojia2 = xuanze(res, frame, model, cfg, threadPubMsg, camera_id, dic, dic_change, dic_huojia2, dic_change_huojia2, huojia1_id, huojia2_id) #print("22222233333333") #dic, dic_huojia2 = xuanze(res, frame, model, cfg, threadPubMsg, camera_id, dic, dic_change, huojia1_id, huojia2_id) dic_change = dic dic_change_huojia2 = dic_huojia2 HKIPcamera.release()