Skip to content

Commit 3de76b8

Browse files
authored
extracts all frames to directory
1 parent 19d6491 commit 3de76b8

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

object_track.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
55
import shutil
66
import imageio
77

8+
9+
10+
811
def process_image(im):
9-
image, contours, hier = cv2.findContours(im, cv2.RETR_TREE,
12+
image, contours, hierarchy= cv2.findContours(im, cv2.RETR_TREE,
1013
cv2.CHAIN_APPROX_SIMPLE)
11-
12-
# with each contour, draw boundingRect in green
13-
# a minAreaRect in red and
14-
# a minEnclosingCircle in blue
1514
for c in contours:
1615

1716
# get the bounding rect
17+
1818
x, y, w, h = cv2.boundingRect(c)
1919

2020
# draw a green rectangle to visualize the bounding rect
2121
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
22-
22+
# cv2.putText(img,'Tracked',(x-25,y-10),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),2,cv2.CV_AA)
23+
#cv2.putText(img,'(x,y)',(x-25,y-10),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,255),2,cv2.LINE_AA)
24+
#roi = img[r:r+h,c:c+w]
25+
#hsv_roi = cv2.cvtColor(roi,cv2.COLOR_BGR2HSV)
26+
#focus_box = cv2.inRange(hsv_roi,np.array((0., 30., 32.)),np.array((180.,255.,255,)))
27+
2328
# get the min area rect
2429
rect = cv2.minAreaRect(c)
2530
box = cv2.boxPoints(rect)
@@ -39,33 +44,30 @@ def process_image(im):
3944
shutil.rmtree("images")
4045
os.mkdir("images")
4146

42-
43-
# In[13]:
44-
4547
try:
46-
shutil.rmtree('foo.avi')
48+
shutil.rmtree('output.avi')
4749
except:
4850
pass
49-
50-
51-
# In[14]:
52-
53-
filename = 'people-walking.mp4'
54-
vid = imageio.get_reader(filename, 'ffmpeg')
51+
filename = 'vtest.avi'
52+
vid = imageio.get_reader(filename, 'ffmpeg')
5553

5654
for num in range(vid.get_length()):
57-
img = vid.get_data(num)
58-
gray_image = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
59-
_,im = cv2.threshold(gray_image,220,1,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
60-
im = process_image(im)
61-
pylab.imsave("images/"+"image-"+str(num)+".jpg",im)
62-
63-
64-
# In[15]:
65-
66-
os.system('ffmpeg -framerate 25 -i images/image-%00d.jpg -r 76 -s 800x600 foo.avi')
67-
6855

56+
img = vid.get_data(num)
57+
gray_image = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
58+
_,im = cv2.threshold(gray_image,220,1,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
59+
im = process_image(im)
60+
cv2.imshow('image',im)
61+
#fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
62+
fourcc = cv2.VideoWriter_fourcc('F','M','P','4')
63+
#w = int(vid.get(cv2.VID_PROP_FRAME_WIDTH))
64+
#h = int(vid.get(cv2.VID_PROP_FRAME_HEIGHT))
65+
#out = cv2.VideoWriter('output.avi',fourcc,20.0,(w,h))
66+
out = cv2.VideoWriter('output.avi',-1,20.0,(640,480))
67+
#vid.release()
68+
pylab.imsave("images/"+"image-"+str(num)+".jpg",im)
69+
70+
os.system('ffmpeg -framerate 25 -i images/image-%00d.jpg -r 76 -s 800x600 output.avi')
6971

7072

7173

0 commit comments

Comments
 (0)