Beispiel #1
0
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()
Beispiel #2
0
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()
Beispiel #3
0
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()
Beispiel #4
0
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()
Beispiel #5
0
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()