Ejemplo n.º 1
0
def setup():
	global cam, theBlobDetection, numPixels, backgroundPixels, newFrame, mode, bg, img
	mode = 0
	size(640/2, 480/2)
	cameras = Capture.list()
	
	if len(cameras) == 0:
		print("There are no cameras available for capture.")
		exit()
	else:
		print("Available cameras:")
		for i,camera in enumerate(cameras):
			print(i,camera)
	
	# The camera can be initialized directly using an 
	# element from the array returned by list():
	cam = Capture(this, cameras[7])
	cam.start()
	newFrame = False	# is the frame ready yet?
	
	# BlobDetection
	img = PImage(width,height)
	bg = PImage(width,height)  
	theBlobDetection = BlobDetection(img.width, img.height)
	theBlobDetection.setPosDiscrimination(True)
	theBlobDetection.setThreshold(0.2) # will detect bright areas whose luminosity > 0.2f;
  
  	# Background subtraction
	numPixels = width * height;
	backgroundPixels = [0]*numPixels  # Create a list to store the background image
	loadPixels();
Ejemplo n.º 2
0
class ImageProcessor(Thread):
	def __init__(self, color, debug=False):
		super(ImageProcessor, self).__init__()
		self.stream = io.BytesIO()
		self.event = Event()
		self.terminated = False
		self.process_time = 0
		self.color = color
		self.debug = debug
		self.blob = BlobDetection(debug=False, path="./images/test/")
		self.start()

	def run(self):
		# This method runs in a separate thread
		global iteration, lock, pool, BestBlob
		while not self.terminated:
			# Wait for an image to be written to the stream
			if self.event.wait(1):
				try:
					self.stream.seek(0)
					# Read the image and do some processing on it
					# Construct a numpy array from the stream
					data = np.fromstring(self.stream.getvalue(), dtype=np.uint8)
					image = cv2.imdecode(data, 1)
					if self.debug:
						print '\nIteration: ', iteration,
					if iteration%10: #Save every 10th image
						blob_detected = self.blob.detect(image, self.color, save=False)
					else:
						blob_detected = self.blob.detect(image, self.color, save=True)
					if blob_detected:
						BestBlob = [self.blob.best_keypoint_x, self.blob.best_keypoint_y]
						BestBlob = [self.blob.best_keypoint_x, 150]
						if self.debug:
							print ' Blob: ', BestBlob
					else:
						BestBlob = []
						print " No blob"
					iteration += 1

				finally:
					# Reset the stream and event
					self.stream.seek(0)
					self.stream.truncate()
					self.event.clear()
					# Return ourselves to the pool
					with lock:
						pool.append(self)
Ejemplo n.º 3
0
	def __init__(self, color, debug=False):
		super(ImageProcessor, self).__init__()
		self.stream = io.BytesIO()
		self.event = Event()
		self.terminated = False
		self.process_time = 0
		self.color = color
		self.debug = debug
		self.blob = BlobDetection(debug=False, path="./images/test/")
		self.start()