def Testors():
import cv, cv2
class Testor(object):
def __init__(self):
#self.cap = cv2.VideoCapture(0)
#self.cap.set(3,640)
#self.cap.set(4,480)
self.timestamp = time.time()
self.font = cv2.FONT_HERSHEY_SIMPLEX
self.t = Trawler()
def loop(self):
while(1):
p = self.t.fish()
if(p):
self.showbars(p)
if cv2.waitKey( 10) == 27:
break
#time.sleep(1/30)
def showbars(self, pixels):
self.now = time.time()
self.timedelt = self.now - self.timestamp
self.timestamp = self.now
im = np.zeros((480,640,3), np.uint8)
im2 = np.copy(im)
mids = np.array(range(32))*20 + 10
for i in range(len(pixels)):
xoff = i*20
pixcol = np.array(pixels[i])
barheit = int((np.sum(pixcol)/3.0) * 400)
#print "i, pixcol, barheit: %d: %s, %d" % (i, str(pixcol), barheit)
# opencv is bgr rgb
# 210 012
#pixcol.reverse()
pc = pixcol*255
cv2.rectangle(im2, (0+xoff, 0), (20+xoff, 479), (255,255,255), 1)
cv2.rectangle(im2, (0+xoff, 40), (20+xoff, 40+barheit), pc, cv.CV_FILLED)
#if( i < 30):
# p1 = (mids[i], 480-int(amp_values[i]*460+10))
# p2 = (mids[i+1], 480-int(amp_values[i+1]*460+10))
# cv2.line(im2, p1, p2, (0,255,0))
#print "[pixel list of %d][%s]" % (len(pixels), str(pixels[0]))
delt = "FR: %0.1f, px: %d, %s, %s" % (1/self.timedelt, len(pixels), str(im2.shape), str(self.timestamp))
#delt = "^: %0.1f, px: %d" % (timedelt, len(pixels))
cv2.putText( im2, delt, (30, 20), self.font, .4,
(0, 0, 255), 1, cv2.CV_AA)
cv2.imshow('show bars', im2)
t = Testor()
t.loop()
评论列表
文章目录