-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPi3 & Odroid cam_benchmark
82 lines (73 loc) · 2.68 KB
/
Pi3 & Odroid cam_benchmark
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
# USAGE
# python fps_demo.py
# python fps_demo.py --display 1
# import the necessary packages
from __future__ import print_function
from imutils.video import WebcamVideoStream
from imutils.video import FPS
import argparse
import imutils
import cv2
import pdb
import numpy as np
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-n", "--num-frames", type=int, default=100,
help="# of frames to loop over for FPS test")
ap.add_argument("-d", "--display", type=int, default=-1,
help="Whether or not frames should be displayed")
ap.add_argument("-s", "--save-frames", type=int, default=-1,
help="# Whether or not to save image frames to ./images/")
ap.add_argument("-b", "--brightest-pixel", type=int, default=-1,
help="# Whether or not to find location of brightest pixel")
args = vars(ap.parse_args())
# created a *threaded *video stream, allow the camera senor to warmup,
# and start the FPS counter
print("[INFO] sampling THREADED frames from webcam...")
vs = WebcamVideoStream(src=0).start()
fps = FPS().start()
i = 0 #Only for testing brightest_pixel logic
# loop over some frames...this time using the threaded stream
while fps._numFrames < args["num_frames"]:
# grab the frame from the threaded video stream and resize it
# to have a maximum width of 400 pixels
frame = vs.read()
frame = imutils.resize(frame, width=1280)
# check to see if the frame should be displayed to our screen
if args["display"] > 0:
cv2.imshow("Frame", frame)
key = cv2.waitKey(1) & 0xFF
if args["save_frames"] > 0:
cv2.imwrite(("./images/img"+ str(fps._numFrames)+".jpg"), frame)
if args["brightest_pixel"] > 0:
if i == 0:
size = np.transpose(frame.shape) #Horizontal dimension array
decVal = 3
dec_frame = np.empty((size[0]//decVal, size[1])) #Just considering as a 2D matrix (not 3D)
j = 0 #change to i
ran = range(0, (size[0] -size[0]%decVal) -1, decVal)
for r in ran:
k = 0 #change to j
for c in range (0, size[1]-1):
dec_frame.itemset((j, k), frame[r, c, 0])
k+=1
j+=1
print("Input frame size: " + str(frame.shape))
print("Decimated frame size using one of every "+ str(decVal) + " rows: " + str(dec_frame.shape))
a = np.random.randint(20, size=(6,7))
indices = np.where(a == a.max())
row = indices[0]
column = indices[1]
out = [row[0], column[0]]
print(a)
print(out)
i += 1
# update the FPS counter
fps.update()
# stop the timer and display FPS information
fps.stop()
print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
# do a bit of cleanup
cv2.destroyAllWindows()
vs.stop()