def update(self, dt): self.img = GameInstance().cam.getImage().flipHorizontal() hsv = self.img.toHSV() mask = cv2.inRange(hsv.getNumpy(), GameInstance().lower, GameInstance().upper) img2 = Image(source=mask) img2 = img2.erode(1) img2 = img2.dilate(2) blops = img2.findBlobs() if blops: largest = blops[-1] x, y = largest.centroid() y = self.size[1] - y self.movement_filter(numpy.array([x, y])) self.blob_coor[0] = x self.blob_coor[1] = y if self.last_pos[1] is not None: with self.game.canvas: kvColor(1, 1, 0) d = 10. # Ellipse(pos=(x - d / 2, self.blob_coor[1] - d / 2), size=(d, d)) Line(points=(self.last_pos[0][0], self.last_pos[0][1], self.last_pos[1][0], self.last_pos[1][1])) self.last_pos[0] = self.last_pos[1]
def encuentraYFiltraBlobs(self,areaMin, areaMax, toleranciaWH, desviacionD, toleranciaLP, tipoDibujo): imagenBlobs = Image(self.rutaImagenTratada_Fase2).copy() blobs = imagenBlobs.findBlobs() self.todosLosCandidatos = blobs if blobs: blobs.image = imagenBlobs self.areaBlobs = blobs.area() blobs = self.filtroPorArea(blobs, areaMin, areaMax) self.numBlobsCandidatosPorArea = len(blobs) # Busca los blobs de forma circular , los blobs que pasan el filtro # se guardan en la lista self.articulaciones blobs = self.filtroPorForma(blobs, toleranciaWH, desviacionD, toleranciaLP) if tipoDibujo == 'blobs': self.dibujaBlobs(blobs) elif tipoDibujo == 'estructura': self.dibujaEstructura(imagenBlobs) # La imagen tratada tiene que ser guardada porque sino no funciona # la integracion con Tkinter imagenBlobs.save(self.rutaImagenBlobs) return Image(self.rutaImagenBlobs)
def check_image(image_path): #Find file by path and import. File currently resides in same directory. image = Image(image_path) # grey = image.grayscale() instruction = "go" array_bounds_possible_widths = [image.width / 4, image.width / 4 * 3] shapes_pic_attributes = image.size() shapes_pic_size = shapes_pic_attributes[0] * shapes_pic_attributes[1] # dist = img.colorDistance(SimpleCV.Color.Black).dilate(2) blobs = image.findBlobs() #check if the blob is in the middle 1/2 of screen and is too high for blob in blobs[:-1]: # print blob.contains() if (blob.coordinates()[0] > array_bounds_possible_widths[0] and blob.coordinates()[0] < array_bounds_possible_widths[1] ) and (blob.height() > image.height / 5 and blob.coordinates()[1] > image.height / 5 * 2): # print grey.height print blob.coordinates()[1] print "Blob is in the way!!" blob.draw(color=(255, 0, 0)) instruction = "stop" # Display the blob until you click on the left side of the picture. display = SimpleCV.Display() while display.isNotDone(): image.show() if display.mouseLeft: break return instruction
def encuentraYFiltraBlobs(self, tipoDibujo='estructura'): imagenBlobs = Image(self.rutaImagenTratada_Fase2).copy() blobs = imagenBlobs.findBlobs() self.todosLosCandidatos = blobs if blobs != []: blobs.image = imagenBlobs self.areaBlobs = blobs.area() blobs = self.filtroPorArea(blobs) self.numBlobsCandidatosPorArea = len(blobs) # Busca los blobs de forma circular , los blobs que pasan el filtro # se guardan en la lista self.articulaciones blobs = self.filtroPorForma(blobs) if tipoDibujo == 'blobs': self.dibujaBlobs(blobs) elif tipoDibujo == 'estructura': self.listaAngulos = self.encuentraYDibujaAngulos(imagenBlobs) # La imagen tratada tiene que ser guardada porque sino no funciona # la integracion con Tkinter imagenBlobs.save(self.rutaImagenBlobs) return Image(self.rutaImagenBlobs)
def center(filename): image = Image(filename) blobs = image.findBlobs() box = blobs[0].mBoundingBox x = box[0] + box[2] / 2. y = box[1] + box[3] / 2. return [x, y]
def main(): camera = cv2.VideoCapture('video2.avi') background_subtractor = cv2.BackgroundSubtractorMOG() # Store previous tracking image previous_track_image = Image() while camera.isOpened(): is_success, image = camera.read() if is_success: mask = background_subtractor.apply(image, None, 0.1) # Vehicles will be detected from this image track_image = Image(ndimage.median_filter(mask, 3), cv2image=True) blobs = track_image.findBlobs(minsize=250, maxsize=800) if not blobs: # print('No Blobs Found.') continue else: # print("Width: {0}; Height: {1}".format(blobs[0].width(), blobs[0].height())) # Only keep near square blobs blobs = filter(lambda b: 0.25 < b.width() / b.height() < 4, blobs) # print("Found {0} Blobs. {1}".format(len(blobs))) if len(vehicle_track_set_list) == 0: # Find first batch of blobs for blob in blobs: blob.drawRect(color=Color.BLUE, width=3, alpha=225) # bounding_box = tuple(blob.boundingBox()) # print("Area: {0}".format(blob.area())) track_set = track_image.track(method='mftrack', img=track_image, bb=blob.boundingBox()) if track_set: vehicle_track_set_list.append(VehicleTrackSet(track_set)) track_set.drawBB(color=(255, 0, 0)) track_set.drawPath() track_image.show() else: for blob in blobs: blob.drawRect(color=Color.BLUE, width=3, alpha=225) # print("Blob Coordinate: ({0}, {1}).".format(blob.x, blob.y)) update_track_set(track_image, previous_track_image, blob.boundingBox()) # Save current image previous_track_image = track_image # time.sleep(0.1) else: camera.release() break
def run(self): cam_mode=self.cam_mode wsh = self.wsh js = self.js wsh2 = self.wsh2 d = "n" c2 = self.c2 c = self.c sqx = self.sqx sqy = self.sqy x = 0 y = 0 stat="live cam" if cam_mode == 3: img1 = c2.getImage() if cam_mode==1: img1 = c.getImage() time.sleep(1) with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img2 = Image('imagesmall.jpg') time.sleep(.5) img1 = img1.sideBySide(img2) img1 = img1.scale(544,288) time.sleep(.5) if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') self.img1 = img1 blobs = img1.findBlobs() if blobs : ##blobs.draw() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) blobx1 = blobs[-1].x bloby1 = blobs[-1].y print blobx1 print bloby1 img1.drawText("ogp: live cam", 10, 10, fontsize=50) img1.drawText(str(blobx1), blobx1, 250, color=(255,255,255), fontsize=20) img1.drawText(str(bloby1), 10, bloby1, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) sqx2=sqx+20 sqy2=sqy+20 time.sleep(.5) wsh.write_message(wsh2, "live") else: wsh.write_message(wsh2, "live")
def filter_to_point(filter, imgname): img = Image(imgname) zones = img.colorDistance(filter).invert() blobs = zones.binarize(230) blobs.findBlobs().draw(color=Color.BLACK, width=20) blobs.save('blobs.bmp') blobs_img = Image('blobs.bmp').invert() points = blobs_img.findBlobs(minsize=100).coordinates() return list(points[0])
def update(self, dt): self.img = GameInstance().cam.getImage().flipHorizontal() GameInstance().lower = np.array((float(self.val[0]), float(self.val[1]), float(self.val[2]))) GameInstance().upper = np.array((float(self.val[3]), float(self.val[4]), float(self.val[5]))) hsv = self.img.toHSV() mask = cv2.inRange(hsv.getNumpy(), GameInstance().lower, GameInstance().upper) img2 = Image(source=mask) img2 = img2.erode(1) img2 = img2.dilate(2) if self.cvActiveBloops.active: blops = img2.findBlobs() if blops: self.cvBlob.texture = getKivyTexture(blops[-1].getMaskedImage()) self.cvFilter.texture = getKivyTexture(img2) self.cvImage.texture = getKivyTexture(self.img)
def get_puzzle_from_image(raw_image): # Returns None if no puzzle found # Returns puzzle, x offset, y offset # if puzzle found. Offsets are top # left corner of puzzle # Remove color gray_image = raw_image.grayscale() # Smooth to remove speckle smooth_image = gray_image.gaussianBlur((5,5),0) # Convert to Numpy Array For OpenCV use cv_image = smooth_image.getGrayNumpyCv2() # Adaptive threshold does much better than linear raw_thresh_image = cv2.adaptiveThreshold(cv_image,255,1,1,11,2) # Convert back to a SimpleCV image thresh_image = Image(raw_thresh_image) # For some reason it gets rotated and flipped, reverse thresh_image = thresh_image.rotate90().flipVertical() # Find "blobs" which are interesting items in the image blobs = thresh_image.findBlobs() # Assume the largest rectangular blob is our puzzle puzzle_blob = None puzzle_area = 0 for blob in blobs: if blob.isRectangle() and blob.area() > puzzle_area: puzzle_blob = blob puzzle_area = blob.area() # Only continue if there is a puzzle if puzzle_blob is None: return None, 0, 0 # Crop image to just the puzzle puzzle_image = puzzle_blob.crop() offset_x, offset_y = puzzle_blob.topLeftCorner() return puzzle_image, offset_x, offset_y
def update(self, dt): self.img = GameInstance().cam.getImage().flipHorizontal() GameInstance().lower = np.array( (float(self.val[0]), float(self.val[1]), float(self.val[2]))) GameInstance().upper = np.array( (float(self.val[3]), float(self.val[4]), float(self.val[5]))) hsv = self.img.toHSV() mask = cv2.inRange(hsv.getNumpy(), GameInstance().lower, GameInstance().upper) img2 = Image(source=mask) img2 = img2.erode(1) img2 = img2.dilate(2) if self.cvActiveBloops.active: blops = img2.findBlobs() if blops: self.cvBlob.texture = getKivyTexture( blops[-1].getMaskedImage()) self.cvFilter.texture = getKivyTexture(img2) self.cvImage.texture = getKivyTexture(self.img)
def update(self, dt): self.img = GameInstance().cam.getImage().flipHorizontal() hsv = self.img.toHSV() mask = cv2.inRange(hsv.getNumpy(), GameInstance().lower, GameInstance().upper) img2 = Image(source=mask) img2 = img2.erode(1) img2 = img2.dilate(2) blops = img2.findBlobs() if blops: largest = blops[-1] x, y = largest.centroid() y = self.size[1]-y self.movement_filter(numpy.array([x, y])) self.blob_coor[0] = x self.blob_coor[1] = y if self.last_pos[1] is not None: with self.game.canvas: kvColor(1, 1, 0) d = 10. # Ellipse(pos=(x - d / 2, self.blob_coor[1] - d / 2), size=(d, d)) Line(points=(self.last_pos[0][0], self.last_pos[0][1],self.last_pos[1][0], self.last_pos[1][1])) self.last_pos[0] = self.last_pos[1]
def run(self): wsh = self.wsh ## c = self.c js = self.js wsh2 = self.wsh2 acu = int(1) acd = int(1) acl = int(1) acr = int(1) irpic = pinoir2(js) img1 = Image('imagesmall.jpg') blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx1 = blobs[-1].x acy1 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) d = 'r' ms = 50 s.write('4') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx2 = blobs[-1].x acy2 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) d = 'd' ms = 50 s.write('9') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx3 = blobs[-1].x acy3 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) d = 'l' ms = 50 s.write('2') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx4 = blobs[-1].x acy4 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx4), 100, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy4), 100, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) d = 'u' ms = 50 s.write('6') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx5 = blobs[-1].x acy5 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx4), 100, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy4), 100, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx5), 130, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy5), 130, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) cal1 = acx1 - acx2 cal2 = acy2 - acy3 cal3 = acx3 - acx4 cal4 = acy4 = acy5 time.sleep(2) wsh.write_message( wsh2, "x_" + str(cal1) + "_" + str(cal2) + "_" + str(cal3) + "_" + str(cal4))
from SimpleCV import Image import time #using opencv captured image, but purpose is make by video call(“raspistill -n -t 0 -w %s -h %s -o image.bmp” % 640 480, shell=True) img = Image(“image.bmp”) img.show() time.sleep(5) #-------- cam = Camera() img = cam.getImage() #----- img = img.edges() img.show() time.sleep(5) img = img.binarize() img.show() time.sleep(5) img = img.findBlobs() for blob in blobs: blob.draw() img.show() time.sleep(5) #연속적인 이미지 촬영으로 영상을 만들면 속도가 너무 느리다 한방으로 가자
from SimpleCV import Camera, Display, Image import time img = Image('logo') blobs = img.findBlobs(100) print blobs #Prints out #[SimpleCV.Features.Blob.Blob object at (146, 28) with area 20, SimpleCV.Features.Blob.Blob object at (182, 218) with area 63, SimpleCV.Features.Blob.Blob object at (116, 31) with area 70, SimpleCV.Features.Blob.Blob object at (119, 222) with area 82, SimpleCV.Features.Blob.Blob object at (103, 218) with area 152, SimpleCV.Features.Blob.Blob object at (56, 222) with area 153, SimpleCV.Features.Blob.Blob object at (198, 222) with area 160, SimpleCV.Features.Blob.Blob object at (81, 222) with area 173, SimpleCV.Features.Blob.Blob object at (161, 219) with area 193, SimpleCV.Features.Blob.Blob object at (135, 215) with area 264, SimpleCV.Features.Blob.Blob object at (125, 125) with area 60792]
def blobs(filename): image = Image(filename) blobs = image.findBlobs() return json.dumps([b.mBoundingBox for b in blobs])
def run(self): cam_mode=self.cam_mode s.write('s') wsh = self.wsh js = self.js wsh2 = self.wsh2 ms = 50 d = "n" acu = int(1) acd = int(1) acl = int(1) acr = int(1) c2=self.c2 sqx=self.sqx sqy=self.sqy x=0 y=0 stat="centering" if cam_mode == 3: img1 = c2.getImage() if cam_mode==1: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') self.img1 = img1 blobs = img1.findBlobs() if blobs : ##blobs.draw() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) blobx1 = blobs[-1].x bloby1 = blobs[-1].y print blobx1 print bloby1 img1.drawText("ogp: centering", 10, 10, fontsize=50) img1.drawText(str(blobx1), 10, 200, color=(255,255,255), fontsize=50) ##img1.drawText(str(bloby1), 50, 200, color=(255,255,255), fontsize=50) img1.drawText(str(bloby1), 10, 250, color=(255,255,255), fontsize=50) img1.save(js.framebuffer) sqx2=sqx+20 sqy2=sqy+20 if blobx1 > sqx2: d = '_r' s.write('4') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() wsh.write_message(wsh2, "g_"+ str(d)) if blobx1 < sqx: d = 'l' s.write('2') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() wsh.write_message(wsh2, "g_"+ str(d)) if bloby1 > sqy2: d = 'd' s.write('9') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() wsh.write_message(wsh2, "g_"+ str(d)) if bloby1 < sqy: d = 'u' s.write('6') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() wsh.write_message(wsh2, "g_"+ str(d)) wsh.write_message(wsh2, "c") else: wsh.write_message(wsh2, "c_" + "null" )
def run(self): cam_mode=self.cam_mode wsh = self.wsh js = self.js wsh2 = self.wsh2 d = "n" acu = int(1) acd = int(1) acl = int(1) acr = int(1) c2=self.c2 c=self.c sqx=self.sqx sqy=self.sqy x=0 y=0 stat="centering" if cam_mode == 3: img1 = c2.getImage() if cam_mode==1: img1 = c.getImage() ## with picamera.PiCamera() as camera: ## camera.resolution = (544, 288) ## camera.capture('imagesmall.jpg') ## img1 = Image('imagesmall.jpg') if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') self.img1 = img1 blobs = img1.findBlobs() if blobs : ##blobs.draw() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) blobx1 = blobs[-1].x bloby1 = blobs[-1].y print blobx1 print bloby1 print "sensor" s.write('n') time.sleep(1) position = "altaz_ " + str(s.readline()) wsh.write_message(wsh2, str(position)) img1.drawText("ogp: chasing", 10, 5, fontsize=40) img1.drawText(str(blobx1), blobx1, 250, color=(255,255,255), fontsize=20) img1.drawText(str(bloby1), 10, bloby1, color=(255,255,255), fontsize=20) img1.drawText(str(position), 10, 50, color=(255,255,255), fontsize=25) sqx2=sqx+20 sqy2=sqy+20 img1.drawRectangle(sqx,sqy,20,20,color=(100,100,255)) img1.save(js.framebuffer) if blobx1 > sqx2: d = 'r' s.write('s') time.sleep(.5) wsh.write_message(wsh2, "g_"+ str(d)) if blobx1 < sqx: d = 'l' s.write('q') time.sleep(.5) wsh.write_message(wsh2, "g_"+ str(d)) if bloby1 > sqy2: d = 'd' s.write('a') time.sleep(.5) wsh.write_message(wsh2, "g_"+ str(d)) if bloby1 < sqy: d = 'u' s.write('w') time.sleep(.5) wsh.write_message(wsh2, "g_"+ str(d)) time.sleep(.5) wsh.write_message(wsh2, "c") else: wsh.write_message(wsh2, "c" ) wsh.write_message(wsh2, "CAPTURE" )
smooth_image = gray_image.gaussianBlur((5,5),0) # Convert to Numpy Array For OpenCV use cv_image = smooth_image.getGrayNumpyCv2() # Adaptive threshold does much better than linear raw_thresh_image = cv2.adaptiveThreshold(cv_image,255,1,1,11,2) # Convert back to a SimpleCV image thresh_image = Image(raw_thresh_image) # For some reason it gets rotated and flipped, reverse thresh_image = thresh_image.rotate90().flipVertical() # Find "blobs" which are interesting items in the image blobs = thresh_image.findBlobs() # Assume the largest rectangular blob is our puzzle puzzle_blob = None puzzle_area = 0 for blob in blobs: if blob.isRectangle() and blob.area() > puzzle_area: puzzle_blob = blob puzzle_area = blob.area() # Only continue if there is a puzzle #if puzzle_blob is None: return # Crop image to just the puzzle puzzle_image = puzzle_blob.crop()
def histo(self): cam_mode = self.cam_mode js = self.js ms = self.ms w = self.w cent = 0 rgb1 = 0 c2 = self.c2 wsh = self.wsh wsh2 = self.wsh2 s.write('s') if cam_mode == 3: img1 = c2.getImage() if cam_mode == 1: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') if cam_mode == 2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') self.img1 = img1 blobs = img1.findBlobs() if blobs: print "blob" x = self.x y = self.y p = self.p p = p + 1 img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[0].centroid()), 10, color=(255, 100, 100)) print blobs[-1].meanColor() rgb1 = blobs[-1].meanColor() cent = blobs[-1].centroid() pth1 = "/var/www/images/image" pth3 = ".png" pth = pth1 + str(p) + pth3 print pth img1.save(pth) thumbnail = img1.crop(150, 25, 250, 250) thumbnail = thumbnail.scale(20, 20) thumb1 = "/var/www/images/thumbs/thumb" thumb3 = ".png" thumbpath = thumb1 + str(p) + thumb3 print thumbpath thumbnail.save(thumbpath) self.p = p mySet.add((p, x, y, w, cent, rgb1)) self.mySet = mySet wshx = str(self.x) wshy = str(self.y) centroidx = int(cent[0]) centroidy = int(cent[1]) rcolor = rgb1[0] gcolor = rgb1[1] bcolor = rgb1[2] rcolor = int(rcolor) gcolor = int(gcolor) bcolor = int(bcolor) wsh.write_message( wsh2, "rgb_" + str(rcolor) + "_" + str(gcolor) + "_" + str(bcolor)) wsh.write_message(wsh2, "x_" + str(centroidx) + "_" + str(centroidy)) img1.save(js.framebuffer) wsh.write_message(wsh2, "d_" + wshx + "_" + wshy + "_" + str(p)) else: wshx = str(self.x) wshy = str(self.y) wsh.write_message(wsh2, wshx + " " + wshy + "dark") print "dark"
def histo(self): ## this def is the "light meter" part--- cam_mode = self.cam_mode ## the pic gets cataloged if true --- js = self.js w = self.w cent = 0 rgb1 = 0 c2 = self.c2 wsh = self.wsh wsh2 = self.wsh2 i=0 brightpixels=0 darkpixels=0 blobs = 0 if cam_mode == 3: ## sort out the confusing cam modes img1 = c2.getImage() time.sleep(.25) if cam_mode==1: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') blobs = img1.findBlobs() time.sleep(0.5) if blobs: ##find the blob centroid and cut it out 20x20 crop1 = blobs[-1].x crop2 = blobs[-1].y crop3 = crop1 - 10 crop4 = crop2 - 10 thumbnail = img1.crop(crop3,crop4,20,20) img2 = thumbnail hist = img2.histogram(20) ## split the thumb into 20 levels of darkness brightpixels = hist[10] ## 10 is where the darkest of the light pixels accumulate print brightpixels ##while i < 20: ##old code for if you want to split the histogram in two ##if (i < 10): ##darkpixels = darkpixels + hist[i] ##self.darkpixels = darkpixels ##print hist[i] ##else: ##brightpixels = brightpixels + hist[i] ##self.brightpixels = brightpixels ##print hist[i] ##i = i + 1 if (brightpixels<400): ## heres where it decides to catalog the pic or not... wsh.write_message(wsh2, "histo_" + str(darkpixels) + "_" + str(brightpixels)) print "blob" x = self.x y = self.y p = self.p p = p + 1 thumb1 = "/var/www/html/images/thumbs/thumb" thumb3 = ".png" thumbpath = thumb1 + str(p) + thumb3 print thumbpath thumbnail.save(thumbpath) img1.drawText("blob = True", 10, 35, color=(255,255,255),fontsize=30) img1.drawText("search_mode", 10, 5, color=(0,0,255),fontsize=40) img1.drawText("blob centroid", blobs[-1].x,blobs[-1].y, color=(255,255,255),fontsize=20) img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,0)) img1.drawCircle((blobs[0].centroid()),10,color=(255,255,255)) print blobs[-1].meanColor() rgb1 = blobs[-1].meanColor() cent = blobs[-1].centroid() pth1 = "/var/www/html/images/image" pth3 = ".png" pth = pth1 + str(p) + pth3 print pth img1.save(pth) time.sleep(0.5) self.p = p mySet.add((p,x,y,w,cent,rgb1)) self.mySet = mySet wshx = str(self.x) wshy = str(self.y) centroidx = int(cent[0]) centroidy=int(cent[1]) rcolor=rgb1[0] gcolor=rgb1[1] bcolor=rgb1[2] rcolor=int(rcolor) gcolor=int(gcolor) bcolor=int(bcolor) wsh.write_message(wsh2, "rgb_" + str(rcolor)+"_"+str(gcolor)+"_"+str(bcolor)) wsh.write_message(wsh2, "x_" + str(centroidx)+"_"+str(centroidy)) img1.save(js.framebuffer) time.sleep(0.5) wsh.write_message(wsh2, "d_" + wshx + "_" + wshy + "_" + str(p) ) else: print "senosor dark" print darkpixels,'_', brightpixels blobs = 0 wsh.write_message(wsh2, "histo_" + str(darkpixels) + "_" + str(brightpixels)) else: wshx = str(self.x) wshy = str(self.y) wsh.write_message(wsh2, wshx + " " + wshy + "dark") img1.save(js.framebuffer) print "no blob"
statusWin.addstr( 1, 1, str(object.meanColor())) num_corners = len(corners) statusWin.addstr(2,1, "Corners Found:" + str(num_corners)) corners.draw() img.addDrawingLayer(object.dl()) # circle tracking #dist = img.colorDistance(Color.BLACK).dilate(2) #segmented = dist.stretch(200,255) blobs = img.findBlobs() if blobs: circles = blobs.filter([b.isCircle(0.2) for b in blobs]) if circles: img.drawCircle((circles[-1].x, circles[-1].y), circles[-1].radius(),Color.BLUE,3) img.save("/dev/shm/p4.png") #img.save(js.framebuffer) elif keyp == 'v': pz.stop()
def run(self): wsh = self.wsh ## c = self.c js = self.js wsh2 = self.wsh2 acu = int(1) acd = int(1) acl = int(1) acr = int(1) irpic = pinoir2(js) img1 = Image('imagesmall.jpg') blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx1 = blobs[-1].x acy1 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) d = 'r' ms = 50 s.write('4') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx2 = blobs[-1].x acy2 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) d = 'd' ms = 50 s.write('9') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx3 = blobs[-1].x acy3 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) d = 'l' ms = 50 s.write('2') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx4 = blobs[-1].x acy4 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx4), 100, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy4), 100, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) d = 'u' ms = 50 s.write('6') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx5 = blobs[-1].x acy5 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx4), 100, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy4), 100, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx5), 130, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy5), 130, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) cal1 = acx1 - acx2 cal2 = acy2 - acy3 cal3 = acx3 - acx4 cal4 = acy4 = acy5 time.sleep(2) wsh.write_message(wsh2, "x_" + str(cal1) + "_" + str(cal2) + "_" + str(cal3)+ "_" + str(cal4) )
def histo(self): cam_mode = self.cam_mode js = self.js ms = self.ms w = self.w cent = 0 rgb1 = 0 c2 = self.c2 wsh = self.wsh wsh2 = self.wsh2 s.write('s') if cam_mode == 3: img1 = c2.getImage() if cam_mode==1: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') self.img1 = img1 blobs = img1.findBlobs() if blobs: print "blob" x = self.x y = self.y p = self.p p = p + 1 img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[0].centroid()),10,color=(255,100,100)) print blobs[-1].meanColor() rgb1 = blobs[-1].meanColor() cent = blobs[-1].centroid() pth1 = "/var/www/images/image" pth3 = ".png" pth = pth1 + str(p) + pth3 print pth img1.save(pth) thumbnail = img1.crop(150,25,250,250) thumbnail = thumbnail.scale(20,20) thumb1 = "/var/www/images/thumbs/thumb" thumb3 = ".png" thumbpath = thumb1 + str(p) + thumb3 print thumbpath thumbnail.save(thumbpath) self.p = p mySet.add((p,x,y,w,cent,rgb1)) self.mySet = mySet wshx = str(self.x) wshy = str(self.y) centroidx = int(cent[0]) centroidy=int(cent[1]) rcolor=rgb1[0] gcolor=rgb1[1] bcolor=rgb1[2] rcolor=int(rcolor) gcolor=int(gcolor) bcolor=int(bcolor) wsh.write_message(wsh2, "rgb_" + str(rcolor)+"_"+str(gcolor)+"_"+str(bcolor)) wsh.write_message(wsh2, "x_" + str(centroidx)+"_"+str(centroidy)) img1.save(js.framebuffer) wsh.write_message(wsh2, "d_" + wshx + "_" + wshy + "_" + str(p) ) else: wshx = str(self.x) wshy = str(self.y) wsh.write_message(wsh2, wshx + " " + wshy + "dark") print "dark"
def detectBlobs(image_file): original = Image(image_file) blobs = original.findBlobs() for blob in blobs: blob.drawMinRect(color=Color.RED,width =10) #blobs[-1].drawMinRect(color=Color.RED,width =10) blobs.image = original #original.save("foundBlobs.jpg") return 1