예제 #1
0
def lv1_HDR_proc(lv1_in_queue,lv2_in_queue):
    frame1 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    frame2 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    frame3 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    frame4 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    info('lv1')
    while True:
        try:
            v=lv1_in_queue.get() #get
            if v is None:
                break
            if v[1] == 1:  #v[1] == f2q
                lv2_in_queue.put((parallel_CCRF(v[0],frame1),0)) # frame1 + frame2 --> calc1
                frame2 = v[0]
            elif v[1] ==2: #v[1] == f4q
                lv2_in_queue.put((parallel_CCRF(v[0],frame2),1)) # frame2 + frame3 --> calc2
                #calc4 = parallel_CCRF(calc2[0],calc1[0])     # calc1 + calc2 --> calc4
                frame3 = v[0]
            elif v[1] ==3: #v[1] == f8q
                lv2_in_queue.put((parallel_CCRF(v[0],frame3),2)) # frame3 + frame4 --> calc3
                #calc5 = parallel_CCRF(calc3[0],calc2[0])     # calc2 + calc3 --> calc5
                #result_HDR = parallel_CCRF(calc5,calc4)
                #lv1_out_queue.put(result_HDR) #put
                frame4 = v[0]
            elif v[1] == 0: #v[1] ==fq
                frame1 = v[0]
            #print(result)
            #process v
        except queue.Empty:
            continue
        except Exception as e:
            raise e
예제 #2
0
def lv3_HDR_proc(lv3_in_queue,lv3_out_queue):
    calc4 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    calc5 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    #result_HDR =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    HDR_FRAME = np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    #cv2.namedWindow("HDR", cv2.WND_PROP_FULLSCREEN)
    #cv2.setWindowProperty("HDR",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
    init_time = time.time()
    info('lv3')
    while True:
        lv3_out_queue.put(HDR_FRAME) 
        try:
            v=lv3_in_queue.get() #get
            if v is None:
                break
            if v[1] == 1:
                #lv3_out_queue.put(parallel_CCRF(v[0],calc4)) #calc5 + calc4 -->HDR_frame
                HDR_FRAME = parallel_CCRF(v[0],calc4)
                print("Time taken to spit one HDR frame = ",time.time()-init_time)
                init_time = time.time()
                calc5 = v[0]
            elif v[1] == 0: # got calc4 frame
                calc4 = v[0]
        except queue.Empty:
            continue
        except Exception as e:
            raise e
예제 #3
0
def lv2_HDR_proc(lv2_in_queue,lv3_in_queue):
    calc1 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    calc2 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    calc3 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    info('lv2')
    while True:
        try:
            v=lv2_in_queue.get() #get
            if v is None:
                break
            if v[1] == 1:
                lv3_in_queue.put((parallel_CCRF(v[0],calc1),0)) # calc2 + calc1 --> calc4
                calc2 = v[0]
            elif v[1] == 2:
                lv3_in_queue.put((parallel_CCRF(v[0],calc2),1)) # calc3 + calc2 --> calc5
                calc3 = v[0]
            elif v[1] == 0:
                calc1 = v[0]
        except queue.Empty:
            continue
        except Exception as e:
            raise e
예제 #4
0
def f(in_queue, out_queue):
    while True:
        try:
            v = in_queue.get()
            f1 = np.zeros((300, 400), np.uint8)
            f2 = np.zeros((300, 400), np.uint8)
            result = parallel_CCRF(f1, f2)
            print("child block:\n", result)
            if v is None:
                break
            #print(result)
            #process v
            v = cv2.cvtColor(v, cv2.COLOR_BGR2GRAY)
            out_queue.put(v)
        except:
            continue
예제 #5
0
def HDR_proc(in_queue,out_queue):
    frame1 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    frame2 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    frame3 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    frame4 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    calc1 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    calc2 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    calc3 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    calc4 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    calc5 =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    result_HDR =np.zeros((FRAME_HEIGHT,FRAME_WIDTH),np.uint8)
    init_time = time.time()
    while True:
        try:
            v=in_queue.get() #get
            if v is None:
                break
            if v[1] == 1:  #v[1] == f2q
                calc1 = (parallel_CCRF(v[0],frame1),0) # frame1 + frame2 --> calc1
                frame2 = v[0]
            elif v[1] ==2: #v[1] == f4q
                calc2 = (parallel_CCRF(v[0],frame2),1) # frame2 + frame3 --> calc2
                calc4 = parallel_CCRF(calc2[0],calc1[0])     # calc1 + calc2 --> calc4
                frame3 = v[0]
            elif v[1] ==3: #v[1] == f8q
                calc3 = (parallel_CCRF(v[0],frame3),2) # frame3 + frame4 --> calc3
                calc5 = parallel_CCRF(calc3[0],calc2[0])     # calc2 + calc3 --> calc5
                result_HDR = parallel_CCRF(calc5,calc4)
                print("Time taken to spit one HDR frame = ",time.time()-init_time)
                init_time = time.time()
                out_queue.put(result_HDR) #put
                frame4 = v[0]
            elif v[1] == 0: #v[1] ==fq
                frame1 = v[0]
            #print(result)
            #process v
        except queue.Empty:
            continue
        except Exception as e:
            raise e
예제 #6
0
def run_single_camera(cam):
    """
    This function acts as the body of the example; please see NodeMapInfo example
    for more in-depth comments on setting up cameras.

    :param cam: Camera to run example on.
    :type cam: CameraPtr
    :return: True if successful, False otherwise.
    :rtype: bool
    """

    try:
        # Initialize camera
        cam.Init()

        configure_settings(cam)

        # Retrieve GenICam nodemap
        nodemap = cam.GetNodeMap()
        exposures = [(2**i) * int(base_exposure(cam)) for i in range(0, 4)]
        print(exposures)
        index = 0

        #configure the trigger
        if configure_trigger(cam) is False:
            return False

        if cam.ExposureAuto.GetAccessMode() != PySpin.RW:
            print("Unable to disable automatic exposure. Aborting...")
            return False
        node_acquisition_mode = PySpin.CEnumerationPtr(
            nodemap.GetNode("AcquisitionMode"))
        if not PySpin.IsAvailable(
                node_acquisition_mode) or not PySpin.IsWritable(
                    node_acquisition_mode):
            print(
                "Unable to set acquisition mode to continuous (enum retrieval). Aborting..."
            )
            return False

        # Retrieve entry node from enumeration node
        node_acquisition_mode_continuous = node_acquisition_mode.GetEntryByName(
            "Continuous")
        if not PySpin.IsAvailable(
                node_acquisition_mode_continuous) or not PySpin.IsReadable(
                    node_acquisition_mode_continuous):
            print(
                "Unable to set acquisition mode to continuous (entry retrieval). Aborting..."
            )
            return False

        acquisition_mode_continuous = node_acquisition_mode_continuous.GetValue(
        )

        node_acquisition_mode.SetIntValue(acquisition_mode_continuous)

        print("Acquisition mode set to continuous...")

        print("Automatic exposure disabled...")
        #node_acquisition_framerate = PySpin.CFloatPtr(nodemap.GetNode("AcquisitionFrameRate"))

        # if not PySpin.IsAvailable(node_acquisition_framerate) and not PySpin.IsReadable(node_acquisition_framerate):
        #     print("Unable to retrieve frame rate. Aborting...")
        #     return False

        # framerate_to_set = node_acquisition_framerate.GetValue()

        # print("Frame rate to be set to %d..." % framerate_to_set)
        canvas = np.zeros((FRAME_HEIGHT * 2, FRAME_WIDTH * 2, 1), np.uint8)
        cam.BeginAcquisition()
        err, img, width, height = acquire_images(cam, nodemap)
        if err < 0:
            return err
        half_frame_height = int(FRAME_HEIGHT / 2)
        half_frame_width = int(FRAME_WIDTH / 2)
        half_height = int(height / 2)
        half_width = int(width / 2)

        bot = half_height - half_frame_height
        top = half_height + half_frame_height
        left = half_width - half_frame_width
        right = half_width + half_frame_width
        init_time = time.time()
        while True:
            #exposure=exposures[index]

            configure_exposure(cam, exposures[index])
            # Acquire images
            err, img, width, height = acquire_images(cam, nodemap)

            img = img.GetData().reshape(height, width, 1)

            img = img[bot:top, left:right]
            #smallimg=cv2.resize(img,(int(FRAME_WIDTH/2),int(FRAME_HEIGHT/2)))
            #print(cam.AcquisitionFrameRate.GetValue())
            if index == 0:
                #top left
                topleft = img
                canvas[0:FRAME_HEIGHT, 0:FRAME_WIDTH] = img
            elif index == 1:
                #top right
                topright = img
                canvas[0:FRAME_HEIGHT, FRAME_WIDTH:FRAME_WIDTH * 2] = img
                calc1 = parallel_CCRF(topright, topleft)
            elif index == 2:
                #bot left
                botleft = img
                canvas[FRAME_HEIGHT:FRAME_HEIGHT * 2, 0:FRAME_WIDTH] = img
                calc2 = parallel_CCRF(botleft, topright)
            else:
                #bot right
                botright = img
                canvas[FRAME_HEIGHT:FRAME_HEIGHT * 2,
                       FRAME_WIDTH:FRAME_WIDTH * 2] = img
                calc3 = parallel_CCRF(botright, botleft)  #frame 3,4
                calc4 = parallel_CCRF(calc2, calc1)
                calc5 = parallel_CCRF(calc3, calc2)
                HDR_FRAME = parallel_CCRF(calc5, calc4)
                print("Time taken to spit one HDR frame = ",
                      time.time() - init_time)
                init_time = time.time()
                cv2.imshow("HDR", HDR_FRAME / 255)
                if cv2.waitKey(5) & 0xff == ord('q'):
                    break
            index += 1
            if index >= len(exposures):
                index = 0

            cv2.imshow("frame", canvas)
            if cv2.waitKey(1) & 0xff == ord('q'):
                #stop the feed the 'q'
                break
        cv2.destroyAllWindows()
        # Deinitialize camera
        cam.EndAcquisition()
        reset_trigger(cam)
        cam.DeInit()

    except PySpin.SpinnakerException as ex:
        print("Error: %s" % ex)
        result = False