Пример #1
0
def saliency(image):
    saliency_map = FasaSaliencyMapping(image.shape[0], image.shape[1])
    image_salient_1 = saliency_map.returnMask(image,
                                              tot_bins=8,
                                              format='BGR2LAB')
    image_salient = cv2.GaussianBlur(image_salient_1, (3, 3), 1)
    image_salient = cv2.convertScaleAbs(image_salient)
    return image_salient
def main():
    # Open the video stream and set the webcam resolution.
    # It may give problem if your webcam does not support the particular resolution used.
    video_capture = cv2.VideoCapture(0)
    video_capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, RESOLUTION_WIDTH)
    video_capture.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, RESOLUTION_HEIGHT)
    print video_capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
    print video_capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)

    if (video_capture.isOpened() == False):
        print("Error: the resource is busy or unvailable")
        return
    else:
        print("The video source has been opened correctly...")

    # Create the main window and move it
    cv2.namedWindow('Video')
    cv2.moveWindow('Video', 20, 20)

    # Obtaining the CAM dimension
    cam_w = int(video_capture.get(3))
    cam_h = int(video_capture.get(4))

    # Defining the FASA object using the camera resolution
    my_map = FasaSaliencyMapping(cam_h, cam_w)

    while True:
        start = timer()
        # Capture frame-by-frame
        ret, frame = video_capture.read()
        image_salient = my_map.returnMask(frame, tot_bins=8, format='BGR2LAB')
        end = timer()
        # Print the time for processing the frame
        if PRINT_TIME:
            print("--- %s Tot seconds ---" % (end - start))
            print("")
        cv2.imshow('Video', image_salient)
        # Press Q to exit
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
def main():
    # Open the video stream and set the webcam resolution.
    # It may give problem if your webcam does not support the particular resolution used.
    video_capture = cv2.VideoCapture(0)
    video_capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, RESOLUTION_WIDTH)
    video_capture.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, RESOLUTION_HEIGHT)
    print video_capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
    print video_capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)

    if(video_capture.isOpened() == False):
        print("Error: the resource is busy or unvailable")
        return
    else:
        print("The video source has been opened correctly...")

    # Create the main window and move it
    cv2.namedWindow('Video')
    cv2.moveWindow('Video', 20, 20)

    # Obtaining the CAM dimension
    cam_w = int(video_capture.get(3))
    cam_h = int(video_capture.get(4))

    # Defining the FASA object using the camera resolution
    my_map = FasaSaliencyMapping(cam_h, cam_w)

    while True:
        start = timer()
        # Capture frame-by-frame
        ret, frame = video_capture.read()
        image_salient = my_map.returnMask(frame, tot_bins=8, format='BGR2LAB')
        end = timer()
        # Print the time for processing the frame
        if PRINT_TIME: 
            print("--- %s Tot seconds ---" % (end - start))
            print("")
        cv2.imshow('Video', image_salient)
        # Press Q to exit
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
def main():

    image_1 = cv2.imread("./horse.jpg")
    image_2 = cv2.imread("./car.jpg")
    image_3 = cv2.imread("./plane.jpg")
    image_4 = cv2.imread("./pear.jpg")

    # for each image the same operations are repeated
    my_map = FasaSaliencyMapping(image_1.shape[0], image_1.shape[1])  # init the saliency object
    start = timer()
    image_salient_1 = my_map.returnMask(image_1, tot_bins=8, format='BGR2LAB')  # get the mask from the original image
    image_salient_1 = cv2.GaussianBlur(image_salient_1, (3,3), 1)  # applying gaussin blur to make it pretty
    end = timer()
    print("--- %s Image 1 tot seconds ---" % (end - start))

    my_map = FasaSaliencyMapping(image_2.shape[0], image_2.shape[1])
    start = timer()
    image_salient_2 = my_map.returnMask(image_2, tot_bins=8, format='BGR2LAB')
    image_salient_2 = cv2.GaussianBlur(image_salient_2, (3,3), 1)
    end = timer()
    print("--- %s Image 2 tot seconds ---" % (end - start))

    my_map = FasaSaliencyMapping(image_3.shape[0], image_3.shape[1])
    start = timer()
    image_salient_3 = my_map.returnMask(image_3, tot_bins=8, format='BGR2LAB')
    #image_salient_3 = cv2.GaussianBlur(image_salient_3, (3,3), 1)
    end = timer()
    print("--- %s Image 3 tot seconds ---" % (end - start))

    my_map = FasaSaliencyMapping(image_4.shape[0], image_4.shape[1])
    start = timer()
    image_salient_4 = my_map.returnMask(image_4, tot_bins=8, format='BGR2LAB')
    image_salient_4 = cv2.GaussianBlur(image_salient_4, (3,3), 1)
    end = timer()
    print("--- %s Image 4 tot seconds ---" % (end - start))

    # Creating stack of images and showing them on screen
    original_images_stack = np.hstack((image_1, image_2, image_3, image_4))
    saliency_images_stack = np.hstack((image_salient_1, image_salient_2, image_salient_3, image_salient_4))
    saliency_images_stack = np.dstack((saliency_images_stack,saliency_images_stack,saliency_images_stack))
    cv2.imshow("Original-Saliency", np.vstack((original_images_stack, saliency_images_stack)))

    while True:
        if cv2.waitKey(33) == ord('q'):
            cv2.destroyAllWindows()
            break
Пример #5
0
def main():

    for i in range (512): # was 200
        image_1 = cv2.imread("./horse.jpg")
        image_2 = cv2.imread("./car.jpg")
        image_3 = cv2.imread("./plane.jpg")
        image_4 = cv2.imread("./pear.jpg")

        # for each image the same operations are repeated
        my_map = FasaSaliencyMapping(image_1.shape[0], image_1.shape[1])  # init the saliency object
        start = timer()
        image_salient_1 = my_map.returnMask(image_1, tot_bins=8, format='BGR2LAB')  # get the mask from the original image
        image_salient_1 = cv2.GaussianBlur(image_salient_1, (3,3), 1)  # applying gaussin blur to make it pretty
        end = timer()
        #print("--- %s Image 1 tot seconds ---" % (end - start))

        my_map = FasaSaliencyMapping(image_2.shape[0], image_2.shape[1])
        start = timer()
        image_salient_2 = my_map.returnMask(image_2, tot_bins=8, format='BGR2LAB')
        image_salient_2 = cv2.GaussianBlur(image_salient_2, (3,3), 1)
        end = timer()
        #print("--- %s Image 2 tot seconds ---" % (end - start))

        my_map = FasaSaliencyMapping(image_3.shape[0], image_3.shape[1])
        start = timer()
        image_salient_3 = my_map.returnMask(image_3, tot_bins=8, format='BGR2LAB')
        #image_salient_3 = cv2.GaussianBlur(image_salient_3, (3,3), 1)
        end = timer()
        #print("--- %s Image 3 tot seconds ---" % (end - start))

        my_map = FasaSaliencyMapping(image_4.shape[0], image_4.shape[1])
        start = timer()
        image_salient_4 = my_map.returnMask(image_4, tot_bins=8, format='BGR2LAB')
        image_salient_4 = cv2.GaussianBlur(image_salient_4, (3,3), 1)
        end = timer()
        #print("--- %s Image 4 tot seconds ---" % (end - start))

        # Creating stack of images and showing them on screen
        original_images_stack = np.hstack((image_1, image_2, image_3, image_4))
        saliency_images_stack = np.hstack((image_salient_1, image_salient_2, image_salient_3, image_salient_4))
        saliency_images_stack = np.dstack((saliency_images_stack,saliency_images_stack,saliency_images_stack))
        cv2.imshow("Original-Saliency", np.vstack((original_images_stack, saliency_images_stack)))

        cv2.destroyAllWindows()
def main():
    i = 0
    loopNum = 0

    a = open('latency_start.csv', 'a')
    a.write('start' + '\n')
    b = open('latency_end.csv', 'a')
    b.write('end' + '\n')
    c = open('latency_time.csv', 'a')
    c.write('time' + '\n')
    d = open('latency_loop.csv', 'a')
    d.write('loop' + '\n')

    for i in range(10):

        loopNum += 1

        image_1 = cv2.imread("./horse.jpg")
        image_2 = cv2.imread("./car.jpg")
        image_3 = cv2.imread("./plane.jpg")
        image_4 = cv2.imread("./pear.jpg")

        # for each image the same operations are repeated
        my_map = FasaSaliencyMapping(
            image_1.shape[0], image_1.shape[1])  # init the saliency object
        start = timer()
        image_salient_1 = my_map.returnMask(
            image_1, tot_bins=8,
            format='BGR2LAB')  # get the mask from the original image
        image_salient_1 = cv2.GaussianBlur(
            image_salient_1, (3, 3),
            1)  # applying gaussin blur to make it pretty
        end = timer()
        #print("--- %s Image 1 tot seconds ---" % (end - start))

        my_map = FasaSaliencyMapping(image_2.shape[0], image_2.shape[1])
        start = timer()
        image_salient_2 = my_map.returnMask(image_2,
                                            tot_bins=8,
                                            format='BGR2LAB')
        image_salient_2 = cv2.GaussianBlur(image_salient_2, (3, 3), 1)
        end = timer()
        #print("--- %s Image 2 tot seconds ---" % (end - start))

        my_map = FasaSaliencyMapping(image_3.shape[0], image_3.shape[1])
        start = timer()
        image_salient_3 = my_map.returnMask(image_3,
                                            tot_bins=8,
                                            format='BGR2LAB')
        #image_salient_3 = cv2.GaussianBlur(image_salient_3, (3,3), 1)
        end = timer()
        #print("--- %s Image 3 tot seconds ---" % (end - start))

        my_map = FasaSaliencyMapping(image_4.shape[0], image_4.shape[1])
        start = timer()
        image_salient_4 = my_map.returnMask(image_4,
                                            tot_bins=8,
                                            format='BGR2LAB')
        image_salient_4 = cv2.GaussianBlur(image_salient_4, (3, 3), 1)
        end = timer()
        #print("--- %s Image 4 tot seconds ---" % (end - start))

        # Creating stack of images and showing them on screen
        original_images_stack = np.hstack((image_1, image_2, image_3, image_4))
        saliency_images_stack = np.hstack((image_salient_1, image_salient_2,
                                           image_salient_3, image_salient_4))
        saliency_images_stack = np.dstack(
            (saliency_images_stack, saliency_images_stack,
             saliency_images_stack))

        t0 = timer()
        cv2.imshow("Original-Saliency",
                   np.vstack((original_images_stack, saliency_images_stack)))
        t1 = timer()

        while True:
            t4 = timer()
            if cv2.waitKey(33) == ord('q'):
                t2 = timer()
                cv2.destroyAllWindows()
                t3 = timer()
                t5 = timer()
                break

        start = t1 - t0
        end = t3 - t2
        latency = t5 - t4

        a.write(str(start) + '\n')
        b.write(str(end) + '\n')
        c.write(str(latency) + '\n')
        d.write(str(loopNum) + '\n')

    a.close()
    b.close()
    c.close()
    d.close()