-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_sal_def.pyx
executable file
·185 lines (161 loc) · 6.28 KB
/
main_sal_def.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#-------------------------------------------------------------------------------
# Name: main
# Purpose: Testing the package pySaliencyMap
#
# Author: Akisato Kimura <akisato@ieee.org>
#
# Created: May 4, 2014
# Copyright: (c) Akisato Kimura 2014-
# Licence: All rights reserved
#-------------------------------------------------------------------------------
import cv2
import matplotlib.pyplot as plt
import pySaliencyMap
import time
import numpy as np
from generateChannels import generateChannels
from makeBorderOwnership import makeBorderOwnership
# from salienpy.salienpy.commons import minmaxnormalization
# from ittiNorm import ittiNorm
# from numba import vectorize, cuda
from multiprocessing import Process
from makeDefaultParams import makeDefaultParams
from computeTemporalFiltering import computeTemporalFiltering
from normalizeImage import normalizeImage
# main
# @vectorize(['float32(float32)'],target='cuda')
# def static(img):
# # read
# # img = cv2.imread('test3.jpg')
# # initialize
# img = np.transpose(img,[1,2,0])
# imgsize = img.shape
# img_width = imgsize[1]
# img_height = imgsize[0]
# sm = pySaliencyMap.pySaliencyMap(img_width, img_height)
# sm = sm.SMGetSM(img)
# # computation
# # start = time.time()
# # for i in range(100):
# # sal_map = []
# # for i in range(3):
# # sal_map.append()
#
#
#
# return sm
import h5py
import tensorflow as tf
tf.enable_eager_execution()
import cv2
import matplotlib.pyplot as plt
if __name__ == '__main__':
a = sal_map()
# # with h5py.File('./video_explosion.mat', 'r') as f:
# # video = tf.constant(np.transpose(f['video'],[1,0,3,2]))
#
# params = makeDefaultParams(1e5)
# cap= cv2.VideoCapture("/media/yesh/c6023e6a-3832-4c3c-9f34-5e3c280e1f20/yesh_friend/python/sall_skiing.mp4")
# sm = pySaliencyMap.pySaliencyMap(cap.read()[1].shape[0],cap.read()[1].shape[1])
# video =[]
# fr_no = 0
# while (True):
# video = []
# # Capture frame-by-frame
# for i in range(10):
# ret, frame = cap.read()
# video.append(frame)
# start = time.time()
# temp_out_strong, temp_out_weak = computeTemporalFiltering(video, params)
# # sess = tf.Session()
# # size(frames,1),size(frames,2),3,numel(params.channels)
# imgs = np.zeros((video[0].shape[0], video[0].shape[1], video[0].shape[2], len(params['channels'])))
#
# for l in range(temp_out_strong.shape[3]):
# # for l in range(1):
# start = time.time()
#
# imgs[:, :, :, 0] = normalizeImage(tf.squeeze(temp_out_strong[l, :, :, :]))
# imgs[:, :, :, 1] = normalizeImage(tf.squeeze(temp_out_weak[ l,:, :, :]))
# imgs[:, :, :, 2] = normalizeImage(video[l])
# # ChannelFirst
# # img = generateChannels(imgs,params)
# R, G, B, inp = generateChannels(imgs, params)
#
# salmap = sm.sal_map(R, G, B,inp)
# print("time:",time.time()-start,"\n")
# # cv2.imwrite("C:/Users/Sathyaprakash/Desktop/python/images/"+"frame_"+str(l)+".jpg", salmap)
# plt.imsave("/media/yesh/c6023e6a-3832-4c3c-9f34-5e3c280e1f20/yesh_friend/python/images/"+"frame_"+str(fr_no)+".png",salmap,cmap='jet')
# fr_no = fr_no +1
# # plt.show()
# # cv2.waitKey()
#
# # Our operations on the frame come here
# # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#
# # Display the resulting frame
# # cv2.imshow('frame', gray)
# # if cv2.waitKey(1) & 0xFF == ord('q'):
# # break
#
#
#
#
# # [b1Pyr,b2Pyr] = makeBorderOwnership(img,params)
# #
# # # static(normalizeImage(tf.squeeze(temp_out_strong[:, l, :, :])))
# # print(time.time()-start)
# #
# # plt.imshow(0.33 *imgs[:,:,2])
#
# # plt.imshow(0.33*np.sum(imgs[:,:,2]))#,-1))
#
def sal_map():
# with h5py.File('./video_explosion.mat', 'r') as f:
# video = tf.constant(np.transpose(f['video'],[1,0,3,2]))
params = makeDefaultParams(1e5)
cap= cv2.VideoCapture("/media/yesh/c6023e6a-3832-4c3c-9f34-5e3c280e1f20/yesh_friend/python/sall_skiing.mp4")
sm = pySaliencyMap.pySaliencyMap(cap.read()[1].shape[0],cap.read()[1].shape[1])
video =[]
fr_no = 0
while (True):
video = []
# Capture frame-by-frame
for i in range(10):
ret, frame = cap.read()
video.append(frame)
start = time.time()
temp_out_strong, temp_out_weak = computeTemporalFiltering(video, params)
# sess = tf.Session()
# size(frames,1),size(frames,2),3,numel(params.channels)
imgs = np.zeros((video[0].shape[0], video[0].shape[1], video[0].shape[2], len(params['channels'])))
for l in range(temp_out_strong.shape[3]):
# for l in range(1):
start = time.time()
imgs[:, :, :, 0] = normalizeImage(tf.squeeze(temp_out_strong[l, :, :, :]))
imgs[:, :, :, 1] = normalizeImage(tf.squeeze(temp_out_weak[ l,:, :, :]))
imgs[:, :, :, 2] = normalizeImage(video[l])
# ChannelFirst
# img = generateChannels(imgs,params)
R, G, B, inp = generateChannels(imgs, params)
salmap = sm.sal_map(R, G, B,inp)
print("time:",time.time()-start,"\n")
# cv2.imwrite("C:/Users/Sathyaprakash/Desktop/python/images/"+"frame_"+str(l)+".jpg", salmap)
plt.imsave("/media/yesh/c6023e6a-3832-4c3c-9f34-5e3c280e1f20/yesh_friend/python/images/"+"frame_"+str(fr_no)+".png",salmap,cmap='jet')
fr_no = fr_no +1
# plt.show()
# cv2.waitKey()
# Our operations on the frame come here
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
# cv2.imshow('frame', gray)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
# [b1Pyr,b2Pyr] = makeBorderOwnership(img,params)
#
# # static(normalizeImage(tf.squeeze(temp_out_strong[:, l, :, :])))
# print(time.time()-start)
#
# plt.imshow(0.33 *imgs[:,:,2])
# plt.imshow(0.33*np.sum(imgs[:,:,2]))#,-1))
# img = tf.add(imgs,axis=)