Esempio n. 1
0
	def paintGL(self):
		img													= CVtypes.cvRetrieveFrame(self.cap)
		print 'W: %s, H: %s, D: %s, C: %s' % (img[0].width, img[0].height, img[0].depth, img[0].nChannels)
		glClearColor(0.5, 0.5, 0.5, 0.0)
		img_bitmap											= CVtypes.cvImageAsBitmap(img)
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
		glRasterPos2i(0,0)
		glDrawPixels(img[0].width,img[0].height, GL_RGB, GL_UNSIGNED_BYTE, img[0].imageData)
Esempio n. 2
0
	def paintGL(self):
		img_rgb													= CVtypes.cvRetrieveFrame(self.cap)
		# convert bgr to rgb
		CVtypes.cvCvtColor(img_rgb, img_rgb, CVtypes.CV_BGR2RGB)
		CVtypes.cvFlip(img_rgb, None, 1)
		glClearColor(0.5, 0.5, 0.5, 0.0)
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
		#glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)
		glRasterPos2i(0,0)
		#glDrawPixels(self.img_width,self.img_height, GL_RGBA, GL_UNSIGNED_BYTE, self.image)
		glDrawPixels(img_rgb[0].width,img_rgb[0].height, GL_RGB, GL_UNSIGNED_BYTE, img_rgb[0].imageData)
Esempio n. 3
0
 def paintGL(self):
     img_rgb = CVtypes.cvRetrieveFrame(self.cap)
     # convert bgr to rgb
     CVtypes.cvCvtColor(img_rgb, img_rgb, CVtypes.CV_BGR2RGB)
     CVtypes.cvFlip(img_rgb, None, 1)
     glClearColor(0.5, 0.5, 0.5, 0.0)
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     #glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)
     glRasterPos2i(0, 0)
     #glDrawPixels(self.img_width,self.img_height, GL_RGBA, GL_UNSIGNED_BYTE, self.image)
     glDrawPixels(img_rgb[0].width, img_rgb[0].height, GL_RGB,
                  GL_UNSIGNED_BYTE, img_rgb[0].imageData)
Esempio n. 4
0
    def getContours(self, image):
        cv.Smooth(image, image, CVtypes.CV_GAUSSIAN, 17, 17)
        #cv.CvtColor(image,self.modifiedImage,CVtypes.CV_GRAY2RGB);
        cv.Threshold(image, image, 128, 255, CVtypes.CV_THRESH_BINARY)
        #cv.CvtColor(image,self.modifiedImage,CVtypes.CV_GRAY2RGB);
        cv.Canny(image, image, 50, 200)

        #cv.CvtColor(image,self.modifiedImage,CVtypes.CV_GRAY2RGB);
        #cv.CvtColor(self.grayImage,self.modifiedImage,CVtypes.CV_GRAY2RGB);
        #cv.Copy(frame,self.modifiedImage)
        #return
        contour = POINTER(cv.Seq)()
        if 1:
            cv.FindContours(
                image,
                #self.grayImage,
                self.cvStorage[0],
                byref(contour),
                sizeof(cv.Contour),
                CVtypes.CV_RETR_CCOMP,
                CVtypes.CV_CHAIN_APPROX_SIMPLE,
                cv.Point(0, 0),
            )
        contourBlocks = []
        if contour:
            cSeq = cast(contour, POINTER(cv.Seq))
            ellipses = []
            while cSeq:
                contours = []
                total = cSeq[0].total
                if total >= 6:
                    box = cv.FitEllipse2(cSeq)
                    ellipses.append(box)
                #print
                #print
                for i in range(total):
                    next = CVtypes.CV_GET_SEQ_ELEM(cv.Seq, cSeq, i)
                    nContour = cast(next, POINTER(cv.Contour))
                    rect = nContour[0].rect
                    contours.append(rect)
                    #print rect
                contourBlocks.append(contours)
                cSeq = cast(cSeq[0].h_next, POINTER(cv.Seq))
        #print ellipses[0]
        #print
        if 1:
            if contourBlocks:
                bboxes = []
                for contours in contourBlocks:
                    c0 = contours[0]
                    bbox = [self.size[0] + 1, self.size[1] + 1, -1, -1]
                    for i, c in enumerate(contours):
                        #if i==(len(contours)-1): break
                        x0, y0, x1, y1 = c.x, c.y, c.width, c.height
                        if ((x0 > self.size[0]) or (x1 > self.size[0])
                                or (y0 > self.size[1]) or (y1 > self.size[1])
                                or (x0 <= 0) or (x1 <= 0) or (y0 <= 0)
                                or (y1 <= 0)):
                            x0, y0, x1, y1 = c0.x, c0.y, c0.width, c0.height
                            continue
                        if x0 < bbox[0]: bbox[0] = x0
                        if x1 < bbox[0]: bbox[0] = x0
                        if x0 > bbox[2]: bbox[2] = x0
                        if x1 > bbox[2]: bbox[2] = x0
                        if y0 < bbox[1]: bbox[1] = y0
                        if y1 < bbox[1]: bbox[1] = y0
                        if y0 > bbox[3]: bbox[3] = y0
                        if y1 > bbox[3]: bbox[3] = y0
                        cv.Line(
                            self.modifiedImage,
                            cv.Point(x0, y0),
                            cv.Point(x1, y1),
                            #cv.Point(contours[i+1].x,contours[i+1].y),
                            CVtypes.CV_RGB(255, 0, 0),
                            1,
                            1,
                        )
                    bboxes.append(bbox)
                for bbox in bboxes:
                    cv.Rectangle(
                        self.modifiedImage,
                        cv.Point(bbox[0], bbox[1]),
                        cv.Point(bbox[2], bbox[3]),
                        CVtypes.CV_RGB(0, 255, 255),
                        1,
                        8,
                    )
                cx, cy = 0, 0
                num = 0
                for e in ellipses:
                    x = e.center.x
                    y = e.center.y
                    center = cv.Point(int(x), int(y))
                    size = cv.Size(int(e.size.width), int(e.size.height))
                    if size.width > self.size[0] or size.height > self.size[1]:
                        continue
                    cx += x
                    cy += y
                    num += 1
                    angle = -e.angle
                    cv.Ellipse(
                        self.modifiedImage,
                        center,
                        size,
                        angle,
                        0,
                        360,
                        CVtypes.CV_RGB(0, 255, 255),
                    )
                if num:
                    cx /= num
                    cy /= num
                    cv.Circle(
                        self.modifiedImage,
                        cv.Point(int(cx), int(cy)),
                        20,
                        CVtypes.CV_RGB(255, 255, 0),
                    )

        cv.DrawContours(
            self.modifiedImage,
            contour,
            CVtypes.CV_RGB(255, 0, 0),
            CVtypes.CV_RGB(0, 255, 0),
            1,
            1,
        )