def get_saliency_features(img):
#     img = np.array(img)
    saliency = Saliency(img).get_saliency_map()
    binary_saliency = np.where(saliency>3*saliency.mean(), 1, 0).astype('uint8')
    prop_background = 1 - binary_saliency.mean()
    
    n_components, output, stats, centroids = cv2.connectedComponentsWithStats(binary_saliency)
    sizes = stats[:, -1]
    countours = stats[:, :-1]
    max_component_size = max(sizes)/img.shape[0]/img.shape[1]
    bbox = countours[np.argmax(sizes)]
    max_component_avg_saliency = saliency[bbox[1]:bbox[3], bbox[0]:bbox[2]].mean()
    s = centroids/[img.shape[0], img.shape[1]]
    dist = euclidean_distances(s)
    mean_dist = dist[~np.eye(dist.shape[0], dtype=bool)].mean()
    max_component_centorid = s[np.argmax(sizes)]
    min_dist_from_third_points = min(
        np.linalg.norm(max_component_centorid - [1/3, 1/3]),
        np.linalg.norm(max_component_centorid - [1/3, 2/3]),
        np.linalg.norm(max_component_centorid - [2/3, 1/3]),
        np.linalg.norm(max_component_centorid - [2/3, 2/3]),
    )
    dist_from_center = np.linalg.norm(s - [0.5, 0.5], axis=1)
    mean_dist_from_center = dist_from_center.mean()
    sum_dist_from_center = dist_from_center.sum()
    
    return np.array([prop_background, n_components, max_component_size, max_component_avg_saliency, mean_dist, min_dist_from_third_points, mean_dist_from_center, sum_dist_from_center])
def main(video_file='soccer.avi', roi=((140, 100), (500, 600))):
    # open video file
    if path.isfile(video_file):
        video = cv2.VideoCapture(video_file)
    else:
        print 'File "' + video_file + '" does not exist.'
        raise SystemExit

    # initialize tracker
    mot = MultipleObjectsTracker()

    while True:
        # grab next frame
        success, img = video.read()
        if success:
            if roi:
                # original video is too big: grab some meaningful ROI
                img = img[roi[0][0]:roi[1][0], roi[0][1]:roi[1][1]]

            # generate saliency map
            sal = Saliency(img, use_numpy_fft=False, gauss_kernel=(3, 3))

            cv2.imshow('original', img)
            cv2.imshow('saliency', sal.get_saliency_map())
            cv2.imshow('objects', sal.get_proto_objects_map(use_otsu=False))
            cv2.imshow('tracker', mot.advance_frame(img,
                       sal.get_proto_objects_map(use_otsu=False)))

            if cv2.waitKey(100) & 0xFF == ord('q'):
                break
        else:
            break
Example #3
0
def main(video_file='soccer.avi', roi=((140, 100), (500, 600))):
    # open video file
    if path.isfile(video_file):
        video = cv2.VideoCapture(video_file)
    else:
        print 'File "' + video_file + '" does not exist.'
        raise SystemExit

    # initialize tracker
    mot = MultipleObjectsTracker()

    while True:
        # grab next frame
        success, img = video.read()
        if success:
            if roi:
                # original video is too big: grab some meaningful ROI
                img = img[roi[0][0]:roi[1][0], roi[0][1]:roi[1][1]]

            # generate saliency map
            sal = Saliency(img, use_numpy_fft=False, gauss_kernel=(3, 3))

            cv2.imshow('original', img)
            cv2.imshow('saliency', sal.get_saliency_map())
            cv2.imshow('objects', sal.get_proto_objects_map(use_otsu=False))
            cv2.imshow(
                'tracker',
                mot.advance_frame(img,
                                  sal.get_proto_objects_map(use_otsu=False)))

            if cv2.waitKey(100) & 0xFF == ord('q'):
                break
        else:
            break
Example #4
0
def main(video_file='jet.mp4', region=((0, 0), (350, 450))):
    # open video file

    if path.isfile(video_file):
        video = cv2.VideoCapture(video_file)
    else:
        print 'File "' + video_file + '" does not exist.'
        raise SystemExit

    # initialize tracker
    mot = MultipleObjectsTracker()

    while True:
        # grab next frame
        success, img = video.read()
        if success:
            if region:
                #original video is too big: grab some meaningful region of interest
                img = img[region[0][0]:region[1][0], region[0][1]:region[1][1]]

            # generate saliency map
            sal = Saliency(img)

            cv2.imshow('original', img)
            cv2.imshow('saliency', sal.get_saliency_map())
            cv2.imshow('objects', sal.get_proto_objects_map())
            cv2.imshow('tracker',
                       mot.advance_frame(img, sal.get_proto_objects_map()))

            if cv2.waitKey(100) & 0xFF == ord('q'):
                break
        else:
            break
Example #5
0
def get_saliency_map(arr):
    size = arr.shape[0] * arr.shape[1]
    sali = Saliency(arr)
    m = sali.get_saliency_map()
    sali_stats = getstats(m)
    cnt = (m > 0.80).sum()
    cnt2 = (m > 0.9).sum()
    cnt3 = (m < 0.1).sum()
    cnt4 = (m < 0.2).sum()
    return sali_stats + [
        cnt, cnt / size, cnt2, cnt2 / size, cnt3, cnt3 / size, cnt4,
        cnt4 / size
    ]
Example #6
0
 def get_saliency(self):
     self.ui.stackedWidget.setCurrentIndex(2)
     if self.ui.inputLabel.pixmap() is not None:
         self.ui.outputLabel.loadPixmapData(
             QPixmap.fromImage(
                 image_to_qimage(
                     Saliency.execute(
                         qpixmap_to_pil_image(self.ui.inputLabel.pixmap()),
                         self.get_settings()))))
Example #7
0
def sal_image(frame_queue, sal_queue, queue_lock):
  print "sal_image called"
  frame = 0
  while True:
    if not frame_queue.empty():       
        queue_lock.acquire()
        img = frame_queue.get()
        queue_lock.release()
        
        sal = Saliency(img)
        sal_map = sal.get_saliency_map()
        sal_img = (sal_map*255).round().astype(np.uint8)
        img = cv2.cvtColor(sal_img, cv2.COLOR_GRAY2BGR)

        queue_lock.acquire()
        if sal_queue.qsize() < 3:
          sal_queue.put(img)
        else:
          time.sleep(1)
        queue_lock.release()
        frame = frame + 1
        print "SAL _ FRAME : ", frame
def main(video_file='soccer.avi', roi=((140, 100), (500, 600))):
    if path.isfile(video_file):
        video = cv2.VideoCapture(video_file)
    elif video_file == 'camera':
        video = cv2.VideoCapture(0)
    else:
        print 'File "' + video_file + '" does not exist.'
        raise SystemExit

    mot = MultipleObjectsTracker()
    while True:
        success, img = video.read()
        if success:
            if roi:
                img = img[roi[0][0]:roi[1][0], roi[0][1]:roi[1][1]]
                #generate saliency map
                sal = Saliency(img, use_numpy_fft=False, gauss_kernel=(3, 3))

        cv2.imshow(
            "tracker",
            mot.advance_frame(img, sal.get_proto_objects_map(use_otsu=False)))

        if cv2.waitKey(100) & 0xFF == ord('q'):
            break
Example #9
0
def main():
    # open video file
    video = cv3.VideoCapture("soccer.avi")

    # initialize tracker
    mot = MultipleObjectsTracker()

    while True:
        # grab next frame
        ret, img = video.read()
        if ret:
            # original video is too big: grab some meaningful ROI
            img = img[140:500, 100:600]

            img = cv3.imread("IMG_1688.JPG")

            # generate saliency map
            sal = Saliency(img, useNumpyFFT=False, gaussKernel=(3, 3))

            cv3.imwrite("magn.jpg", sal.PlotMagnitudeSpectrum())

            cv3.imshow("original", img)
            cv3.imshow("saliency", sal.GetSaliencyMap())
            cv3.imshow("objects", sal.GetProtoObjectsMap(useOtsu=False))
            cv3.imshow(
                "tracker",
                mot.AdvanceFrame(img, sal.GetProtoObjectsMap(useOtsu=False)))

            if cv3.waitKey(100) & 0xFF == ord('q'):
                cv3.imwrite("tracker.jpg", tracker)
                break
        else:
            break

    video.release()
    cv3.destroyAllWindows()
Example #10
0
from matplotlib import pyplot as plt
import time

BUFFER = 40

# read an image
img_original = cv2.imread("test_image.jpg")
img_grayscale = cv2.cvtColor(img_original, cv2.COLOR_BGR2GRAY)
# img_sized = cv2.resize(img_original,(1920,1080))
img_sized = cv2.resize(img_original, (1280, 720))
img_size_exclusion = img_sized.copy()
img_hist = img_sized.copy()

start = time.time()
# find the saliency map
sal = Saliency(img_sized)
sal_map = sal.get_saliency_map()

end = time.time()

test_duration = end - start

# convert to the correct type
sal_conv = (sal_map * 255).round().astype(np.uint8)

# find the contours
ret, thresh = cv2.threshold(sal_conv, 100, 255, 0)
_, contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

color = ("b", "r", "g")
Example #11
0
    def func(cover, stego, scale=1):
        # cover = cover.resize(((cover.size[0] / scale, cover.size[1] / scale)), Image.ANTIALIAS)
        # stego = stego.resize(((stego.size[0] / scale, stego.size[1] / scale)), Image.ANTIALIAS)

        s1 = Saliency(cover, use_numpy_fft=False,
                      gauss_kernel=(3, 3)).get_saliency_map()
        s2 = Saliency(stego, use_numpy_fft=False,
                      gauss_kernel=(3, 3)).get_saliency_map()

        # Image.fromarray(s1*255).show()
        # Image.fromarray(s2*255).show()

        t = np.percentile(s1, salTh)
        s1 = f(s1, t)
        t = np.percentile(s2, salTh)
        s2 = f(s2, t)

        cover = rgb2gray(cover)
        stego = rgb2gray(stego)

        sob1 = sobel(cover)
        sob2 = sobel(stego)

        t = np.percentile(sob1, sobTh)
        sob1 = f(np.uint8(sob1), t)

        t = np.percentile(sob2, sobTh)
        sob2 = f(np.uint8(sob2), t)

        # sob1 = attack(sob1)
        # sob2 = attack(sob2)

        # Image.fromarray(np.uint8(sob2 * 255)).convert('RGB').show()
        # Image.fromarray(np.uint8(out * 255)).convert('RGB').show()
        # Image.fromarray(np.uint8(out1 * 255)).convert('RGB').show()

        # sob1 = ndimage.morphology.binary_erosion(sob1, iterations=2)
        # sob1 = ndimage.morphology.binary_dilation(sob1, iterations=2)

        # sob2 = ndimage.morphology.binary_erosion(sob2, iterations=2)
        # sob2 = ndimage.morphology.binary_dilation(sob2, iterations=2)

        Image.fromarray(np.uint8(
            s1 * 255)).convert('RGB').save("/media/ramdisk/s1.png")
        Image.fromarray(cover).convert('RGB').save("/media/ramdisk/cover.png")
        Image.fromarray(np.uint8(
            sob1 * 255)).convert('RGB').save("/media/ramdisk/sob1.png")

        Image.fromarray(np.uint8(
            s2 * 255)).convert('RGB').save("/media/ramdisk/s2.png")
        Image.fromarray(stego).convert('RGB').save("/media/ramdisk/stego.png")
        Image.fromarray(np.uint8(
            sob2 * 255)).convert('RGB').save("/media/ramdisk/sob2.png")

        # print s1.sum(), s2.sum(), float(s2.sum()) / float(s1.sum())

        # return (float((s1 == s2).sum()) / float(w * h) + ess(cover, stego)) * 0.5
        # return float((s1 == s2).sum()) / float(w * h)
        # return (float(f1(s1, s2).sum()) / float(s1.sum()) + ess(cover, stego)) * 0.5
        # print float(f1(s1, s2).sum()) / float(s1.sum()), float(f1(sob1, sob2).sum()) / float(sob1.sum()), (float(f1(sob1, sob2).sum()) / float(sob1.sum()) + float(f1(s1, s2).sum()) / float(s1.sum())) * 0.5
        # return float(f1(sob1, sob2).sum()) / float(sob1.sum())

        return (float(np.multiply(sob1, sob2).sum()) / float(
            sob1.sum())) * ess_score + (float(np.multiply(s1, s2).sum()) /
                                        float(s1.sum())) * (1 - ess_score)