Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f308deb

Browse filesBrowse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in dcf9821 according to the output from Autopep8. Details: https://app.deepsource.com/gh/avinashkranjan/Amazing-Python-Scripts/transform/5d389ae7-399c-4367-8872-63d7f8b60b9a/
1 parent 0a04746 commit f308deb
Copy full SHA for f308deb

File tree

Expand file treeCollapse file tree

1 file changed

+43
-41
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+43
-41
lines changed
Open diff view settings
Collapse file

‎AirObjects/air.py‎

Copy file name to clipboardExpand all lines: AirObjects/air.py
+43-41Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
# cap = cv2.VideoCapture('NASA_video1.mp4') # video with airplane.
66

77
# patch_size = 15 # Size of image patch to extract around featuns points
8-
patch_size = 25 # Size of image patch to extract around feature points
8+
patch_size = 25 # Size of image patch to extract around feature points
99

1010

11-
count = 0 # Loop counter to control frequency of object recognition
12-
objfreq = 5 # Frequence of object recognition
11+
count = 0 # Loop counter to control frequency of object recognition
12+
objfreq = 5 # Frequence of object recognition
1313
# NumCorners = 50 # Number of corners to extract in a given frame
14-
NumCorners = 10 # Number of corners to extract in a given frame
14+
NumCorners = 10 # Number of corners to extract in a given frame
1515
'''
1616
# fourcc = cv2.cv.CV_FOURCC(*'XVID')
1717
# out = cv2.VideoWriter('result.avi', fourcc, 20.0, (450,170))
@@ -32,31 +32,30 @@
3232
if 1:
3333
if 1:
3434
# Convert to gray scale
35-
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
35+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
3636

3737
# Find corners in gray scale image
38-
corners = cv2.goodFeaturesToTrack(gray,NumCorners,0.01,100)
39-
print 'The corners are:',corners
38+
corners = cv2.goodFeaturesToTrack(gray, NumCorners, 0.01, 100)
39+
print 'The corners are:', corners
4040
corners = np.int0(corners)
4141

4242
# For each corner found, extract a patch and classify patch
43-
for j,i in enumerate(corners):
44-
x,y = i.ravel()
45-
#cv2.circle(frame,(x,y),3,255,-1)
43+
for j, i in enumerate(corners):
44+
x, y = i.ravel()
45+
# cv2.circle(frame,(x,y),3,255,-1)
4646
print 'The x pos of the corner is: ', x
4747
print 'The y pos of the corner is: ', y
4848
print 'The i of the corners is: ', i
4949
print 'The j of the corners is: ', j
5050
# Define size of patch in image coordinates
5151
xstart = x - patch_size
52-
xend = x + patch_size
52+
xend = x + patch_size
5353
ystart = y - patch_size
54-
yend = y + patch_size
55-
54+
yend = y + patch_size
5655

5756
# clip image patch based on image size
58-
xlen = frame.shape[1]
59-
ylen = frame.shape[0]
57+
xlen = frame.shape[1]
58+
ylen = frame.shape[0]
6059

6160
if xend > xlen:
6261
xend = xlen
@@ -67,48 +66,50 @@
6766
yend = ylen
6867
if ystart < 0:
6968
ystart = 0
70-
71-
cv2.rectangle(frame,(xstart,ystart),(xend,yend),(255,0,0),2)
72-
# Extract the image patch from each frame in the video
73-
img_patch = frame[ystart:yend,xstart:xend]
7469

70+
cv2.rectangle(frame, (xstart, ystart),
71+
(xend, yend), (255, 0, 0), 2)
72+
# Extract the image patch from each frame in the video
73+
img_patch = frame[ystart:yend, xstart:xend]
7574

7675
# Transform image to use caffe library
7776
transformed_image = transformer.preprocess('data', img_patch)
78-
77+
7978
# copy the image data into the memory allocated for the net
80-
net.blobs['data'].data[j,:,:,:] = transformed_image
81-
82-
### perform classification
79+
net.blobs['data'].data[j, :, :, :] = transformed_image
80+
81+
# perform classification
8382
output = net.forward()
84-
83+
8584
# Go through image patch for each corner and find if there are any airplanes
8685
Position = []
87-
for i,j in enumerate(corners):
88-
x,y = j.ravel()
89-
output_prob = output['prob'][i]
90-
86+
for i, j in enumerate(corners):
87+
x, y = j.ravel()
88+
output_prob = output['prob'][i]
89+
9190
# sort top five predictions from softmax output
9291
# top_inds = output_prob.argsort()[::-1][:5] # reverse sort and take five largest items
93-
top_inds = output_prob.argsort()[::-1][:10] # reverse sort and take five largest items
94-
print 'The classes are:', top_inds
92+
# reverse sort and take five largest items
93+
top_inds = output_prob.argsort()[::-1][:10]
94+
print 'The classes are:', top_inds
9595
# print 'predicted class is:', output_prob.argmax()
96-
# print 'output label:', labels[output_prob.argmax()]
96+
# print 'output label:', labels[output_prob.argmax()]
9797
# print 'prob', output_prob[top_inds[0]]
9898

9999
# If airlane, record position to draw bounding box
100100

101-
AirplaneLabels = [895,404,405,812] # Airplane label ids in caffe database
102-
#437,566,556,570,706,735,752,818,830,848
103-
#VehicleLabels = [867,717,675,757,569,734,751,817,864,656] # Car, truck, van label ids in caffe database
101+
# Airplane label ids in caffe database
102+
AirplaneLabels = [895, 404, 405, 812]
103+
# 437,566,556,570,706,735,752,818,830,848
104+
# VehicleLabels = [867,717,675,757,569,734,751,817,864,656] # Car, truck, van label ids in caffe database
104105
# for k in range (0,5):
105-
for k in range (0,10):
106-
if (top_inds[k] in AirplaneLabels ):
106+
for k in range(0, 10):
107+
if (top_inds[k] in AirplaneLabels):
107108
if output_prob[top_inds[0]] > 0.0:
108109
print 'Shown class is:', top_inds[k]
109-
print 'output label:', labels[top_inds[k]]
110+
print 'output label:', labels[top_inds[k]]
110111
print 'prob', output_prob[top_inds[k]]
111-
Position.append((x,y))
112+
Position.append((x, y))
112113
# carNum = carNum + 1
113114
# break
114115
# Draw rectangles around each airplane
@@ -117,10 +118,11 @@
117118
for pos in Position:
118119
xpos = pos[0]
119120
ypos = pos[1]
120-
cv2.rectangle(frame,(xpos-patch_size,ypos-patch_size),(xpos+patch_size,ypos+patch_size),(0,255,0),2)
121+
cv2.rectangle(frame, (xpos-patch_size, ypos-patch_size),
122+
(xpos+patch_size, ypos+patch_size), (0, 255, 0), 2)
121123
# break
122124
# out.write(frame)
123-
cv2.imshow('frame',frame)
125+
cv2.imshow('frame', frame)
124126
cv2.waitKey()
125127
# Show image frame on screen
126128
count = count + 1
@@ -133,6 +135,6 @@
133135
if count > cap.get(7)/2:
134136
break
135137
'''
136-
#out.release()
138+
# out.release()
137139
cap.release()
138140
cv2.destroyAllWindows()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.