def Init(self): self.frame = 'none' self.videoCapture = 'none' self.cascade = 'none' self.storage = 'none' cv.NamedWindow("Ex", cv.CV_WINDOW_FULLSCREEN) self.videoCapture = cv.CreateCameraCapture(0) cv.SetCaptureProperty(self.videoCapture,cv.CV_CAP_PROP_FRAME_WIDTH,80) cv.SetCaptureProperty(self.videoCapture,cv.CV_CAP_PROP_FRAME_HEIGHT,60) cv.SetCaptureProperty(self.videoCapture,cv.CV_CAP_PROP_FPS,10) if( self.videoCapture == 'none' ): print("OpenCV error: Could not create cam capture") return self.cascade = cv.Load("./haarcascade_frontalface_alt.xml") self.storage = cv.CreateMemStorage( 0 ) assert(self.cascade and self.storage and self.videoCapture) key = cv.WaitKey(10) while(( key != 'none') and (key != 'q')): self.frame = cv.QueryFrame(self.videoCapture) # if( frame == 'none'): # break # cvFlip(self.frame, self.frame, -1) # self.DetectFaces() cv.ShowImage("videoCapture", self.frame) key = cv.WaitKey(10) return
def detect(image): image_size = cv.GetSize(image) # create grayscale version grayscale = cv.CreateImage(image_size, 8, 1) cv.CvtColor(image, grayscale, cv.BGR2GRAY) # create storage storage = cv.CreateMemStorage(0) cv.ClearMemStorage(storage) # equalize histogram cv.EqualizeHist(grayscale, grayscale) # detect objects cascade = cv.LoadHaarClassifierCascade('haarcascade_frontalface_alt.xml', cv.Size(1, 1)) faces = cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2, cv.HAAR_DO_CANNY_PRUNING, cv.Size(50, 50)) if faces: print 'face detected!' for i in faces: cv.Rectangle(image, cv.Point(int(i.x), int(i.y)), cv.Point(int(i.x + i.width), int(i.y + i.height)), cv.RGB(0, 255, 0), 3, 8, 0) # create windows cv.NamedWindow('Camera', cv.WINDOW_AUTOSIZE) # create capture device device = 0 # assume we want first device capture = cv.CreateCameraCapture(0) cv.SetCaptureProperty(capture, cv.CAP_PROP_FRAME_WIDTH, 640) cv.SetCaptureProperty(capture, cv.CAP_PROP_FRAME_HEIGHT, 480)
def __init__(self): self.capture = cv.CreateCameraCapture(0) cv.SetCaptureProperty(self.capture,cv.CV_CAP_PROP_FRAME_WIDTH,512) cv.SetCaptureProperty(self.capture,cv.CV_CAP_PROP_FRAME_HEIGHT,512) self.image = cv.QueryFrame(self.capture) cv.ShowImage("Capture",self.image) self.size = (self.image.width,self.image.height)
def __init__(self, vid=0, res=None): self._cam = cv.CreateCameraCapture(vid) if res: cv.SetCaptureProperty(self._cam, cv.CV_CAP_PROP_FRAME_WIDTH, res[0]) cv.SetCaptureProperty(self._cam, cv.CV_CAP_PROP_FRAME_HEIGHT, res[1])
def init_cam(self): try: cv.NamedWindow("drillEye", 1) cv.MoveWindow("drillEye", 288, 0) self.capture = cv.CreateCameraCapture(self.camera) except Exception, e: print("Error: %s" % e) exit(0)
def __init__(self, camera_num=0, size=(640, 480)): self.cv_capture = cv.CreateCameraCapture(camera_num) #cv.SetCaptureProperty(self.cv_capture,cv.CV_CAP_PROP_FRAME_WIDTH,1600.0) #cv.SetCaptureProperty(self.cv_capture,cv.CV_CAP_PROP_FRAME_HEIGHT,1200.0) #print cv.GetCaptureProperty(self.cv_capture,cv.CV_CAP_PROP_FRAME_WIDTH) # print cv.GetCaptureProperty(self.cv_capture,cv.CV_CAP_PROP_FRAME_HEIGHT) self.size = size
def setup_camera(self, indx=0, size=(400, 300)): """ setup camera indx = tty/usb device id size = img width, high """ cv.NamedWindow('camera', 1) capture = cv.CreateCameraCapture(indx) cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, size[0]) cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, size[1]) self._capture = capture
def __init__(self, patternFile, inputCameraDeviceId=0, showInWindow=True, analyzeEach=1): self.__detectPattern = cv.Load(patternFile) self.__camera = cv.CreateCameraCapture(int(inputCameraDeviceId)) self.__showInWindow = showInWindow self.__analizeEach = analyzeEach if self.__showInWindow: cv.NamedWindow(self.__windowName, 1)
def main(): cv.NamedWindow("out", 0) cv.MoveWindow("out", 200, 200) cam = cv.CreateCameraCapture(0) while True: frame = cv.QueryFrame(cam) cv.ShowImage("out", frame) if (cv.WaitKey(23) == 'q'): break
def __init__(self, id=0, width=None, height=None): """ Create a new OpenCV Capture Device - if 'id' is integer a 'Camera Device' is used - if 'id' is string a 'Physical Video File' is used """ if type(id) is str: self.capture = cv.CaptureFromFile(id) else: self.capture = cv.CreateCameraCapture(id) cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, width) cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, height)
def init_camera(tmpfile): global tmpimgfile print "Attempting to initalise webcam." camera = cv.CreateCameraCapture(0) cv.SetCaptureProperty(camera, cv.CV_CAP_PROP_FRAME_WIDTH, 384) cv.SetCaptureProperty(camera, cv.CV_CAP_PROP_FRAME_HEIGHT, 288) if not camera: print "Error opening WebCAM" return None else: print "Webcam initalised." return camera
def __init__(self, cameraIndex, parent=None): QWidget.__init__(self) self._capture = cv.CreateCameraCapture(cameraIndex) # Take one frame to query height frame = cv.QueryFrame(self._capture) self.setMinimumSize(frame.width, frame.height) self.setMaximumSize(self.minimumSize()) self._frame = None self._image = self._build_image(frame) # Paint every 50 ms self._timer = QTimer(self) self._timer.timeout.connect(self.queryFrame) self._timer.start(50)
def run(self): global frame1 global frame2 cv2.namedWindow('Sonar Data', cv.CV_WINDOW_AUTOSIZE) cv2.namedWindow('Front Camera', cv.CV_WINDOW_AUTOSIZE) cv2.namedWindow('Ground Cam', cv.CV_WINDOW_AUTOSIZE) cv.MoveWindow('Front Camera', 373, 24) cv.MoveWindow('Ground Cam', 760, 24) cv.MoveWindow('Sonar Data', 60, 24) camera = cv.CreateCameraCapture(self.camID) camera2 = cv.CreateCameraCapture(1) while True: #time.sleep(1) try: #print "raw sonar data", self.sonar.sonar_data sonar_img = sf.sonar_graph(self.sonar.sonar_data) cv.ShowImage('Sonar Data', PILtoCV(sonar_img, 4)) cv.WaitKey(10) del sonar_img except: print "sonar display failure" pass try: frame1 = cv.QueryFrame(camera) frame1 = resize_img(frame1, 0.60) cv.ShowImage('Front Camera', frame1) cv.WaitKey(10) except: print "camera1 display failure" pass try: #frame2 = cv.QueryFrame(camera2) #frame2 = resize_img(frame2, 0.60) frame2 = frame1 cv.ShowImage('Ground Cam', frame2) cv.WaitKey(10) except: print "camera2 display failure" pass
def __init__(self, camera_num=0, size=(640, 480)): ''' Web camera interface for cameras attached to your computer via USB or built-in. For IP/network cameras, use the Video object instead. @param camera_num: The camera index. Usually 0 if you only have a single webcam on your computer. See the OpenCV highgui documentation for details. ''' self.cv_capture = cv.CreateCameraCapture(camera_num) #cv.SetCaptureProperty(self.cv_capture,cv.CV_CAP_PROP_FRAME_WIDTH,1600.0) #cv.SetCaptureProperty(self.cv_capture,cv.CV_CAP_PROP_FRAME_HEIGHT,1200.0) #print cv.GetCaptureProperty(self.cv_capture,cv.CV_CAP_PROP_FRAME_WIDTH) # print cv.GetCaptureProperty(self.cv_capture,cv.CV_CAP_PROP_FRAME_HEIGHT) self.size = size
def __init__(self,namew,width=None,height=None): cv.NamedWindow(namew, 1) self.capture = cv.CreateCameraCapture(0) self.width = width self.height = height if width is None: self.width = int(cv.GetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_WIDTH)) else: cv.SetCaptureProperty(self.capture,cv.CV_CAP_PROP_FRAME_WIDTH,width) if height is None: self.height = int(cv.GetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT)) else: cv.SetCaptureProperty(self.capture,cv.CV_CAP_PROP_FRAME_HEIGHT,height) self.w = cv.CreateImage((self.width,self.height),cv.IPL_DEPTH_8U,3) self.avg = 0 #inizializzazione media
def main(): print "hello world" capture = cv.CreateCameraCapture(0) cv.NamedWindow("test", 1) cv.NamedWindow("result", 1) global h_lower, h_upper, s_lower, s_upper cv.CreateTrackbar("hlow", "result", h_lower, 256, on_track_bar_hlow) cv.CreateTrackbar("hhigh", "result", h_upper, 256, on_track_bar_hhigh) cv.CreateTrackbar("slow", "result", s_lower, 256, on_track_bar_slow) cv.CreateTrackbar("shigh", "result", s_upper, 256, on_track_bar_shigh) while True: image = cv.QueryFrame(capture) get_hand(image) cv.ShowImage("test", image) if(cv.WaitKey(10) != -1): break
def main(): cv.NamedWindow("img", 0) cv.MoveWindow("img", 200, 200) cv.NamedWindow("out", 0) cv.MoveWindow("out", 200, 600) cam = cv.CreateCameraCapture(0); while True: frame = cv.QueryFrame(cam) cv.ShowImage("img", frame) out = process_frame(frame) cv.ShowImage("out", out) print get_pixel_center(out) if (cv.WaitKey(23) == 'q'): break
def __init__(self, camera_num, smallResolution=False): """Initialize and configure camera""" global cam cam = cv.CreateCameraCapture(camera_num) if smallResolution: cv.SetCaptureProperty(cam, cv.CV_CAP_PROP_FRAME_WIDTH, 320) cv.SetCaptureProperty(cam, cv.CV_CAP_PROP_FRAME_HEIGHT, 240) #cv.SetCaptureProperty(self.cam,cv.CV_CAP_PROP_FPS,30) """Create some image variables for using in the processing so that they would not have to be initialized running""" size = (640, 480) if smallResolution: size = (320, 240) self.hsv_frame = cv.CreateImage(size, 8, 3) self.thresholded_frame = cv.CreateImage(size, 8, 1) self.thresholded_field = cv.CreateImage(size, 8, 1) """ Import the threshold values that are set by the thresholds.py program """ f = open('thresholdvalues.txt', 'r') thresholdvalues = f.read() f.close() clrs = thresholdvalues.split() for i in range(len(clrs)): clrs[i] = int(clrs[i]) """Choose the thresholds(variable names speak for them self)""" self.ball_threshold_low = (clrs[0], clrs[1], clrs[2]) self.ball_threshold_high = (clrs[3], clrs[4], clrs[5]) self.blue_gate_threshold_low = (clrs[6], clrs[7], clrs[8]) self.blue_gate_threshold_high = (clrs[9], clrs[10], clrs[11]) self.yellow_gate_threshold_low = (clrs[12], clrs[13], clrs[14]) self.yellow_gate_threshold_high = (clrs[15], clrs[16], clrs[17]) self.black_threshold_low = (clrs[18], clrs[19], clrs[20]) self.black_threshold_high = (clrs[21], clrs[22], clrs[23]) self.white_threshold_low = (clrs[24], clrs[25], clrs[26]) self.white_threshold_high = (clrs[27], clrs[28], clrs[29]) self.green_threshold_low = (clrs[30], clrs[31], clrs[32]) self.green_threshold_high = (clrs[33], clrs[34], clrs[35])
def main_loop(process=None, key_pressed=None): print "Press ESC to exit ..." # creation de la fenetre, redimensionnement automatique cv.NamedWindow('Camera') # webcam ou truc dans le genre ###device = -1 # n'importe laquelle capture = cv.CreateCameraCapture(0) cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 800) cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 600) # si pas de webcam... if not capture: print "Error opening capture device" sys.exit(1) while 1: # capture de l'image frame = cv.QueryFrame(capture) if frame is None: break # simulation d'un mirroir cv.Flip(frame, None, 1) # traitement d'image if process: frame = process(frame) # display webcam image cv.ShowImage('Camera', frame) # handle events k = cv.WaitKey(10) if k == 0x20: # ESPACE print 'ESPACE pressed. Computing.' if key_pressed: frame = key_pressed(frame) if k == 0x1b: # ESC print 'ESC pressed. Exiting ...' cv.DestroyAllWindows() break
def analyze_webcam(width, height): print(""" ' ' : extract colors of detected face 'b' : toggle onlyBlackCubes 'd' : toggle dodetection 'm' : shift right 'n' : shift left 'r' : reset everything 'q' : print hsvs 'p' : resolve colors 'u' : toggle didassignments 's' : save image """) # 0 for laptop camera # 1 for usb camera capture = cv.CreateCameraCapture(0) # Set the capture resolution cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, width) cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, height) # Create the window and set the size to match the capture resolution cv.NamedWindow("Fig", cv.CV_WINDOW_NORMAL) cv.ResizeWindow("Fig", width, height) frame = cv.QueryFrame(capture) rf = RubiksFinder(width, height) while True: frame = cv.QueryFrame(capture) if not frame: cv.WaitKey(0) break rf.analyze_frame(frame) if not rf.process_keyboard_input(): break cv.DestroyWindow("Fig")
def setup_camera_capture(device_num=0): ''' perform camera setup for the device number (default device = 0) i return a reference to the camera Capture ''' try: # try to get the device number from the command line device = int(device_num) except (IndexError, ValueError): # no device number on the command line, assume we want the 1st device device = 0 print 'Using Camera device %d' % device # no argument on the command line, try to use the camera capture = cv.CreateCameraCapture(device) if not capture: print "Error opening capture device" sys.exit(1) return capture
def __init__(self): self.IMAGE_WIDTH = 320 self.IMAGE_HEIGHT = 240 # PID parameters self.KP = 0.035 self.KI = 0.045 self.KD = 0.005 self.prev_errx = 0 self.prev_erry = 0 self.integral_x = 0 self.integral_y = 0 self.curr_yaw = 90 self.curr_pitch = 90 self.last_obs = time.time() # Open the camera self.capture = cv.CreateCameraCapture(0) cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, self.IMAGE_WIDTH) cv.SetCaptureProperty(self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, self.IMAGE_HEIGHT) # Union-Find Connected Comonent Labeling self.detector = BlobDetector() # Kalman filter self.filter = KalmanFilter() # Open the serial port to the arduino print 'Opening serial port ...' self.serial = serial.Serial('/dev/ttyACM0', 19200) time.sleep(2) print 'Moving servos to initial position ...' self.serial.write('90s90t') time.sleep(1)
def getHandsVideo(self, nr): capture = cv.CreateCameraCapture(0) img_width = int(self.default_width / self.rescale_ratio) img_height = int(self.default_height / self.rescale_ratio) #cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, img_width) #cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, img_heigth) #cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FPS, 10) #cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_CONVERT_RGB, 1) index = 0 gray_img = cv.CreateImage((70, 70), cv.IPL_DEPTH_8U, 1) small_img = cv.CreateImage((img_width, img_height), cv.IPL_DEPTH_8U, 3) imgHSV = cv.CreateImage((70, 70), cv.IPL_DEPTH_8U, 3) h_plane = cv.CreateImage((70, 70), cv.IPL_DEPTH_8U, 1) v_plane = cv.CreateImage((70, 70), cv.IPL_DEPTH_8U, 1) while True: index += 1 if (index % 5 == 0): img = cv.QueryFrame(capture) cv.Resize(img, small_img) cv.SetImageROI(small_img, ((int(img_width / 2) - 45), (int(img_height / 2) - 45), 70, 70)) cv.CvtColor(small_img, imgHSV, cv.CV_BGR2HSV) cv.Split(imgHSV, h_plane, None, v_plane, None) #cv.InRangeS(h_plane,2,60,h_plane) cv.InRangeS(v_plane, 130, 360, v_plane) for i in range(0, 70): for j in range(0, 70): if (v_plane[i, j] == 0): small_img[i, j] = (0, 0, 0) cv.CvtColor(small_img, gray_img, cv.CV_BGR2GRAY) cv.EqualizeHist(gray_img, gray_img) cv.ShowImage("camera", gray_img) cv.SaveImage( "train/" + str(nr) + "camera" + str(index) + ".jpg", gray_img) cv.ResetImageROI(small_img) if cv.WaitKey(10) == 27: break
else: adresse = "osc.udp://" + IP + ":" + str(port) target = liblo.Address(adresse) except liblo.AddressError, err: print "Impossible de se connecter au serveur" print str(err) sys.exit() cascade = cv.Load(haarfile) if not cascade: print "Impossible de charger la cascade de classifieurs à l'emplacement " + haarfile + "!" sys.exit(1) #capture une image avec la webcam capture = cv.CreateCameraCapture(webcamID) if showCamera == 1: cv.NamedWindow("result", 1) if capture: frame_copy = None while True: frame = cv.QueryFrame(capture) if not frame: cv.WaitKey(0) break #FAIRE UN TEST SANS FRAME_COPY DU TOUT if not frame_copy: frame_copy = cv.CreateImage((frame.width, frame.height), cv.IPL_DEPTH_8U, frame.nChannels) #s'assure que l'origine de l'image est la bonne
def rightDown(finger): win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, finger[0], finger[1], 0, 0) def rightUp(finger): win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, finger[0], finger[1], 0, 0) #main program if __name__ == '__main__': #capture pake webcam atau pake video capture = cv.CreateCameraCapture(1) #initiate part imageWidth = 0 imageHeight = 0 storage = cv.CreateMemStorage(0) currentFrameSize = (0, 0) fps = 10 camdelay = (1.0 / fps) fixedBorder = 0 telunjukTerangkat = False jariKanan = False jariKiri = False duaJari = False tigaJari = False leftFingerDown = False
def startCapture(self): self.capture = cv.CreateCameraCapture(camera_index) self.captureStarted = True
import sys import cv from hs_histogram import * if __name__ == '__main__': cv.NamedWindow("input", 1) cv.NamedWindow("skinProb", 1) cv.NamedWindow("skinProbThreshH", 1) cv.NamedWindow("skinProbThreshHEroDel", 1) cv.NamedWindow("skinProbColor", 1) cv.NamedWindow("skinProbSmoothed", 1) capture = cv.CreateCameraCapture(int(0)) frameCount = 0 totalTime = 0 imageResize = 0.5 hasHist = False bestFaceX = 0 bestFaceY = 0 bestFaceW = 0 bestFaceH = 0 if capture: inputFrame = None while True: frameCount += 1
import math def work(image): image_size = cv.GetSize(image) grayscale = cv.CreateImage(image_size, 8, 1) cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY) storage = cv.CreateMemStorage(0) cv.EqualizeHist(grayscale, grayscale) return image if __name__ == "__main__": DEVICE = int(sys.argv[1]) if len(sys.argv) > 1 else 0 #/dev/video0 cv.NamedWindow('Camera') capture = cv.CreateCameraCapture(DEVICE) k = '' i = 0 while k != 27: frame = cv.QueryFrame(capture) #cv.RetrieveFrame(capture) if frame is None: break # mirror cv.Flip(frame, None, 1) # face detection frame = work(frame) # display webcam image cv.ShowImage('Camera', frame) # handle events
type="str", help="Haar cascade file, default %default", default= "/usr/local/Cellar/opencv/2.2/share/opencv/haarcascades/haarcascade_frontalface_default.xml" ) (options, args) = parser.parse_args() cascade = cv.Load(options.cascade) if len(args) != 1: parser.print_help() sys.exit(1) input_name = args[0] if input_name.isdigit(): capture = cv.CreateCameraCapture(int(input_name)) else: capture = None cv.NamedWindow("result", 1) if capture: frame_copy = None while True: frame = cv.QueryFrame(capture) if not frame: cv.WaitKey(0) break if not frame_copy: frame_copy = cv.CreateImage((frame.width, frame.height), cv.IPL_DEPTH_8U, frame.nChannels)
def main(): captura = cv.CreateCameraCapture( 1) ##guardamos la imagen de la camara web usb global arra ##cargamos el arreglo de los objetos font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 3, 3) #creamos el fondo para las letras proses = 0 sumaa = 0 while True: img = cv.QueryFrame(captura) #cv.Resize(img,img,cv.CV_INTER_CUBIC) #tiempoi = time.time() #draw = ImageDraw.Draw(img) anch, alt = cv.GetSize(img) ##obtenemos las dimensiones k = cv.WaitKey(10) ##esperemos para cualquier incombeniente #cv.SaveImage("test.jpg",img) cv.Smooth(img, img, cv.CV_GAUSSIAN, 9, 9) ##aplicamos filtro para reducir el ruido #cv.SaveImage("sruido.jpg",img) grey = cv.CreateImage(cv.GetSize(img), 8, 1) ##creamos una imagen en blanco bn = cv.CreateImage(cv.GetSize(img), 8, 1) ##creamos imagen en blanco cv.CvtColor( img, grey, cv.CV_BGR2GRAY ) ###pasamos la imagen a escala de grises y la guardamos en la imagen ne blanco #cv.SaveImage("gris.jpg",grey) cv.ConvertImage(img, bn, 0) ##convertimos la imagen a blancos threshold = 40 ##umbral 1 para binarizacion colour = 255 ## umbral 2 para binarizacion cv.Threshold(grey, grey, threshold, colour, cv.CV_THRESH_BINARY) ##aplicamos binarizacion cv.Canny( grey, bn, 1, 1, 3 ) ##preparamos para obtener contornos, esto nos muestra la imagen con los contornos #cv.SaveImage("cont.jpg",bn) cv.SaveImage("grey.jpg", grey) ##guardamos la imagen cambio("grey.jpg") ##invertimos la imagen y discretisamos imgg = cv.LoadImage( 'ngrey.jpg', cv.CV_LOAD_IMAGE_GRAYSCALE) ##cargamos nuevamente la imagen storage = cv.CreateMemStorage( 0) ##para guardar los puntos y no saturar la memoria contours = cv.FindContours( imgg, storage, cv.CV_RETR_TREE, cv.CV_CHAIN_APPROX_SIMPLE, (0, 0)) ##obtener los puntos de los contornos puntos = [ ] ##para guardar los diferente centros de los objetos y verificarlas posteriormente while contours: ##leemos los contornos nx, ny = contours[ 0] ##para verificar donde se encuentra los centros de la figura u bojeto mx, my = contours[0] ## ancho, altura = cv.GetSize(img) ##obtenemos el tama de la imagen for i in range(len(contours)): ##verificamos las esquinas xx, yy = contours[i] if xx > mx: mx = xx if xx < nx: nx = xx if yy > my: my = yy if yy < ny: ny = yy a, b, c, d = random.randint(0, 255), random.randint( 0, 255), random.randint(0, 255), random.randint(0, 255) ##para el color if len(contours ) >= 50: ##si son mas de 50 puntos es tomada como figura cv.Rectangle(img, (nx, ny), (mx, my), cv.RGB(0, 255, 0), 1, 8, 0) ##pintamos el rectangulo con las esquinas #are = abs(mx-nx)*abs(my-ny) puntos.append((abs(mx + nx) / 2, abs(my + ny) / 2)) ##agregamos los centros #are = abs(mx-nx)*abs(my-ny) contours = contours.h_next( ) #pasamos con los siguientes puntos unidos nuevo = de( puntos, anch, alt ) ##verificamos los objetos y obtenemos los centros de los mismos for i in range(len(nuevo)): ## pintamos la direccin de los mismos x, y, z = nuevo[i] cv.PutText(img, "" + z + "", (x, y), font, 255) tiempof = time.time() ##verificar rendimiento cv.ShowImage('img', img) #cv.SaveImage("final.jpg",img) #tiempoa = tiempof - tiempoi #proses += 1 #sumaa = sumaa + tiempoa #print float(sumaa)/float(proses) #f.write(""+str(proses)+" "+str(tiempoa)+"\n") ##verificar rendimientp if k == 'f': ##si se preciona f se sale break