# BASELINE
import time as t
import picamera
import picamera.array
import cv2
import Constants
import numpy as np
import io
from Filter import Filter as f

camera = picamera.PiCamera()
camera.resolution = (640,480)
camera.framerate = 60
capture = picamera.array.PiRGBArray(camera, size=(640,480))
filt = f(cv2.imread('img/balloon.jpg'), consts=Constants.VIDEOS_CONTOUR_FILTER_CONSTANTS_1, display=False)

camera.start_preview()
t.sleep(5)
camera.stop_preview()

out = ""
time = 0
numFrames = 0

controlFrames = 500
testCount = 3
wantedTestTypes = [1,3]
filtering = True
outputDir = "Notes.txt"

def outputs():
        else:
            # When the pool is starved, wait a while for it to refill
            # print "WAITING!"
            waits += 1
            waitDelay = execTime + 0.08  #Tries to wait for how long the last run was plus a small buffer. Should not run multiple times, 1 time for one thread
            t.sleep(waitDelay)
            # pass


with picamera.PiCamera() as camera:
    pool = [ImageProcessor() for i in range(threadCount)]
    camera.resolution = (640, 480)
    camera.framerate = 30
    camera.start_preview()
    filt = f(cv2.imread('img/balloon.jpg'),
             consts=Constants.VIDEOS_CONTOUR_FILTER_CONSTANTS_1,
             display=False)
    t.sleep(2)
    tot1 = cv2.getTickCount()
    try:
        camera.capture_sequence(streams(), use_video_port=True)
    except:
        print frame
    tot2 = cv2.getTickCount()
    total = (tot2 - tot1) / cv2.getTickFrequency()  # ACCURATE
    cv2.destroyAllWindows()
    camera.close()

    output = "\nTOTAL FILTER TIME:\t " + str(
        time) + "\n\nAVERAGE TIME PER FRAME:\t " + str(
            time / numFrames) + "\n\nAVERAGE FRAMES PER SECOND:\t " + str(
Beispiel #3
0
# cv2.THRESH_BINARY
# cv2.THRESH_BINARY + cv2.THRESH_OTSU
filterTypeNum = 2  # Number to use for filtering listed below
# 1 = Adaptive
# 2 = RGB
# 3 = Binary
size = 35  # Size of box to average for adaptive thresholds
c = 2  # Number to subtract result of adaptive threshold from

approx = cv2.CHAIN_APPROX_SIMPLE  # Contour mappings: Map to shapes or dont map at all listed below
# cv2.CHAIN_APPROX_NONE
# cv2.CHAIN_APPROX_SIMPLE

for item in pics:
    filt = f(
        cv2.imread(item), consts=consts, display=True
    )  # Creates a filter object with the image, constants and displayability
    filt2 = f(cv2.imread(item), consts=consts2,
              display=True)  # Another filter for second attempt
    #grayimg = cv2.cvtColor(img.image, cv2.COLOR_BGR2GRAY)
    #ret, thresh = cv2.threshold(grayimg,127,255,0)
    #blur = cv2.GaussianBlur(grayimg,(5,5),0)
    img = si(
        item
    )  # Creates a savable image (an image that is saveable to the hard drive)
    im = cv2.imread(
        item)  # Reads the same image again, 'im' is the original image
    # blur = filt.blur() # blurs the image using the filter object
    blur = im
    img.showRaw("original")  # shows the image with title 'original'
    cv2.waitKey(0)  # waits 0 milliseconds (forever) for a key to be pressed
Beispiel #4
0
	'minMean' : 0.0,
	'maxMean' : 255.0,
	'minVerticies' : 40,
	'maxVerticies' : 10200,
	'minAngle' : -360.0,
	'maxAngle' : 360.0,
	'minRatioWidthtoSize' : 0.05,
	'maxRatioWidthtoSize' : 0.4,
	'minRatioHeighttoSize' : 0.033,
	'maxRatioHeighttoSize' : 0.4,
	'tolerance' : 24 # Number of above conditions to be met for successful contour observation
}
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
	ret, frame = cap.read()
	if ret==True:
		e1 = cv2.getTickCount() # Starttime
		coolFrame = np.copy(frame) # Copies the frame
		filt = f(frame, consts=consts, display=False) # Filter Object
		ret3, filtered, imagey, contours, h = filt.getContours(cv2.CHAIN_APPROX_SIMPLE, 113, 255, cv2.THRESH_BINARY)#+cv2.THRESH_OTSU)
		coolImage = filt.run(coolFrame)
		cv2.imshow('frame',coolImage)
		if cv2.waitKey(1) & 0xFF == ord('q'):
			break # Quits when you press q
		e2 = cv2.getTickCount()
		time = (e2 - e1) / cv2.getTickFrequency()
		print time
	else:
		break
cap.release()
cv2.destroyAllWindows()
Beispiel #5
0
    'maxVerticies': 10200,
    'minAngle': -360.0,
    'maxAngle': 360.0,
    'minRatioWidthtoSize': 0.05,
    'maxRatioWidthtoSize': 0.4,
    'minRatioHeighttoSize': 0.033,
    'maxRatioHeighttoSize': 0.4,
    'tolerance':
    24  # Number of above conditions to be met for successful contour observation
}
cap = cv2.VideoCapture(0)
while (cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
        e1 = cv2.getTickCount()  # Starttime
        coolFrame = np.copy(frame)  # Copies the frame
        filt = f(frame, consts=consts, display=False)  # Filter Object
        ret3, filtered, imagey, contours, h = filt.getContours(
            cv2.CHAIN_APPROX_SIMPLE, 113, 255,
            cv2.THRESH_BINARY)  #+cv2.THRESH_OTSU)
        coolImage = filt.run(coolFrame)
        cv2.imshow('frame', coolImage)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break  # Quits when you press q
        e2 = cv2.getTickCount()
        time = (e2 - e1) / cv2.getTickFrequency()
        print time
    else:
        break
cap.release()
cv2.destroyAllWindows()
Beispiel #6
0
# cv2.THRESH_BINARY
# cv2.THRESH_BINARY + cv2.THRESH_OTSU
filterTypeNum = 2 # Number to use for filtering listed below
# 1 = Adaptive
# 2 = RGB
# 3 = Binary
size = 35 # Size of box to average for adaptive thresholds
c = 2 # Number to subtract result of adaptive threshold from

approx = cv2.CHAIN_APPROX_SIMPLE # Contour mappings: Map to shapes or dont map at all listed below
# cv2.CHAIN_APPROX_NONE
# cv2.CHAIN_APPROX_SIMPLE


for item in pics:
	filt = f(cv2.imread(item),consts=consts, display=True) # Creates a filter object with the image, constants and displayability
	filt2 = f(cv2.imread(item), consts=consts2, display=True) # Another filter for second attempt
	#grayimg = cv2.cvtColor(img.image, cv2.COLOR_BGR2GRAY)
	#ret, thresh = cv2.threshold(grayimg,127,255,0)
	#blur = cv2.GaussianBlur(grayimg,(5,5),0)
	img = si(item) # Creates a savable image (an image that is saveable to the hard drive)
	im = cv2.imread(item) # Reads the same image again, 'im' is the original image
	# blur = filt.blur() # blurs the image using the filter object
	blur = im
	img.showRaw("original") # shows the image with title 'original'
	cv2.waitKey(0) # waits 0 milliseconds (forever) for a key to be pressed
	img.image = blur # sets the savable image to the blurred image
	img.showRaw("blurred") # shows the blurred iamge with title 'blurred'
	cv2.waitKey(0) 
	if filterTypeNum == 1: # If using adaptive thresholding
		filtered, imagey, contours, h = filt.adaptiveGet(approx, filterHigh, size, c, filterType) # gets the filtered binary image, the original image, the contours, and the hierarchy from the filter object