-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjespersHunt.py
94 lines (71 loc) · 2.82 KB
/
jespersHunt.py
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
import cv2
import numpy as np
import pygame
from pygame.locals import *
# import listening
import connect
#from playsound import playsound
#np.set_printoptions(threshold=np.inf)
#channel = connect.join()
pygame.init()
pygame.mixer.pre_init(44100, 16, 2, 4096)
while(1):
pygame.mixer.music.load('sound/winchester.wav')
# recognition takes a function that is called when keyword is head, the keyword, and if it should keep listening for the keyword
moreGoods = input('Do you want to go hunting?: ').lower()
if moreGoods == 'yes':
print ("SHOOT SHOOOT!")
#playsound('sound/winchester.wav')
#playsound('sound/cow.wav')
# load image
cap = cv2.VideoCapture('vid/hunting.avi', 0)
init_flag = False
while(cap.isOpened()):
# read
ret, img = cap.read()
if ret:
# resize img for transform
img = cv2.resize(img, (16,24), interpolation = cv2.INTER_NEAREST)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# add img together x3 for total transform
#img = np.concatenate((img, img, img), axis=1)
if init_flag == False:
init_state = np.copy(img)
cv2.imshow('init', init_state)
init_flag = True
# uncomment this to see image
#'''
cv2.imshow('image', img)
#cv2.waitKey()
#'''
#Finds differences from initial (static) frame and the following frames with animals moving
dif = np.subtract(img, init_state)
#cv2.imshow('dif', dif)
correct = []
#Threshold to identify pixels that are animals and not just noise
for row,val in enumerate(dif):
for col,val2 in enumerate(val):
if 80 > val2 > 10:
correct.append((row,col))
pygame.mixer.music.play(0,0.0)
print(correct)
# flatten array
img = img.flatten()
# set the frame rate
cv2.waitKey(1000)
# stringify for server
transformSend = ""
for i,ele in enumerate(img):
if i % 3 == 0:
transformSend+=(" "+str(ele))
# if you want to look at the numbers :)
print (transformSend)
# uncomment this to send to server
#channel.push("input",{"body": transformSend})
else:
break
cap.release()
cv2.destroyAllWindows()
else:
print ("Too bad! You have to say yes for this demo to work :)")
cv2.destroyAllWindows()