Ejemplo n.º 1
0
     def show_frame(self):        
                 
         color_image = cv.QueryFrame(self.capture)
        
         color_image1 = cv.CreateImage(cv.GetSize(color_image), 8, 3)
         grey_image = cv.CreateImage(cv.GetSize(color_image), cv.IPL_DEPTH_8U, 1)
         moving_average = cv.CreateImage(cv.GetSize(color_image), cv.IPL_DEPTH_32F, 3)

         grey = cv.CreateImage(cv.GetSize(color_image), 8, 3)
         HSV = cv.CreateImage(cv.GetSize(color_image), 8, 3)
         red = cv.CreateImage(cv.GetSize(color_image), 8, 3)         

         cv.CvtColor(color_image, grey, cv.CV_RGB2HLS)
         cv.CvtColor(color_image, HSV, cv.CV_RGB2HSV)
         cv.Not(color_image, red)

         cv.ShowImage(self.window1, color_image)
         cv.ShowImage(self.window2, grey) 
         cv.ShowImage(self.window3, HSV) 
         cv.ShowImage(self.window4, red)

         cv.MoveWindow(self.window1, 30, 120) 
         cv.MoveWindow(self.window2, 430, 120)
         cv.MoveWindow(self.window3, 430, 470)
         cv.MoveWindow(self.window4, 30, 470)

         while self.arduino.inWaiting() > 0:
            self.data += self.arduino.read(1)
Ejemplo n.º 2
0
 def render_outline_image(image_id, threshold):
     im=cv.LoadImage("Image"+str(image_id)+".bmp", cv.CV_LOAD_IMAGE_COLOR)
     gray = cv.CreateImage((im.width, im.height), 8, 1)
     edge = cv.CreateImage((im.width, im.height), 8, 1)
     im_bw1 = cv.CreateImage((im.width, im.height), 8, 1)
     cv.CvtColor(im, gray, cv.CV_BGR2GRAY)
     cv.Not(gray, edge)
     im_white=cv.LoadImage("white.bmp", cv.CV_LOAD_IMAGE_COLOR)
     white = cv.CreateImage((im_white.width, im_white.height), 8, 1)
     cv.Canny(gray, edge, threshold, 125 * 3, 3)
    # cv.Not(white, edge)
     cv.SaveImage("edge_image.png", edge)
     jpg1 = wx.Image('edge_image.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
     os.remove("edge_image.png")
     return jpg1
Ejemplo n.º 3
0
def on_trackbar(position):

    cv.Smooth(gray, edge, cv.CV_BLUR, 3, 3, 0)
    cv.Not(gray, edge)

    # run the edge dector on gray scale
    cv.Canny(gray, edge, position, position * 3, 3)

    # reset
    cv.SetZero(col_edge)

    # copy edge points
    cv.Copy(im, col_edge, edge)

    # show the im
    cv.ShowImage(win_name, col_edge)
Ejemplo n.º 4
0
    def on_trackbar(self, position):

        cv.Smooth(self.source_image, self.edge, cv.CV_BLUR, 3, 3, 0)
        cv.Not(self.source_image, self.edge)

        # run the edge dector on gray scale
        cv.Canny(self.source_image, self.edge, position, position * 3, 3)

        # reset
        cv.SetZero(self.col_edge)

        # copy edge points
        cv.Copy(self.source_color, self.col_edge, self.edge)

        # show the im
        cv.ShowImage(win_name, self.col_edge)
        self.process_image(position)
Ejemplo n.º 5
0
    def process_image(self, slider_pos):
        """
        This function finds contours, draws them and their approximation by ellipses.
        """
        use_this = self.source_image
        if self.intensity == False:
            cv.Smooth(self.source_image, self.edge, cv.CV_BLUR, 9, 9, 0)
            cv.Not(self.source_image, self.edge)

            # run the edge dector on gray scale
            cv.Canny(self.source_image, self.edge, slider_pos, slider_pos * 3,
                     3)

            # reset
            cv.SetZero(self.col_edge)

            # copy edge points
            cv.Copy(self.source_color, self.col_edge, self.edge)
            use_this = self.edge

        stor = cv.CreateMemStorage()

        # Create the destination images
        image02 = cv.CloneImage(use_this)
        cv.Zero(image02)
        image04 = cv.CreateImage(cv.GetSize(self.source_image),
                                 cv.IPL_DEPTH_8U, 3)
        cv.Zero(image04)

        # Threshold the source image. This needful for cv.FindContours().
        cv.Threshold(use_this, image02, slider_pos, 255, cv.CV_THRESH_BINARY)

        # Find all contours.
        cont = cv.FindContours(image02, stor, cv.CV_RETR_LIST,
                               cv.CV_CHAIN_APPROX_NONE, (0, 0))

        for c in contour_iterator(cont):
            # Number of points must be more than or equal to 6 for cv.FitEllipse2
            if len(c) >= 6:
                # Copy the contour into an array of (x,y)s
                PointArray2D32f = cv.CreateMat(1, len(c), cv.CV_32FC2)
                for (i, (x, y)) in enumerate(c):
                    PointArray2D32f[0, i] = (x, y)

                # Draw the current contour in gray
                gray = cv.CV_RGB(100, 100, 100)
                cv.DrawContours(image04, c, gray, gray, 0, 1, 8, (0, 0))

                # Fits ellipse to current contour.
                (center, size, angle) = cv.FitEllipse2(PointArray2D32f)

                # Convert ellipse data from float to integer representation.
                center = (cv.Round(center[0]), cv.Round(center[1]))
                size = (cv.Round(size[0] * 0.5), cv.Round(size[1] * 0.5))

                # Draw ellipse in random color
                color = cv.CV_RGB(random.randrange(256), random.randrange(256),
                                  random.randrange(256))
                cv.Ellipse(image04, center, size, angle, 0, 360, color, 2,
                           cv.CV_AA, 0)

        # Show image. HighGUI use.
        cv.ShowImage("Result", image04)
cv.AbsDiff(im, im2, res)  # Like minus for each pixel im(i) - im2(i)
cv.ShowImage("AbsDiff", res)

cv.Mul(im, im2, res)  #Multiplie each pixels (almost white)
cv.ShowImage("Mult", res)

cv.Div(im, im2,
       res)  #Values will be low so the image will likely to be almost black
cv.ShowImage("Div", res)

cv.And(im, im2, res)  #Bit and for every pixels
cv.ShowImage("And", res)

cv.Or(im, im2, res)  # Bit or for every pixels
cv.ShowImage("Or", res)

cv.Not(im, res)  # Bit not of an image
cv.ShowImage("Not", res)

cv.Xor(im, im2, res)  #Bit Xor
cv.ShowImage("Xor", res)

cv.Pow(im, res, 2)  #Pow the each pixel with the given value
cv.ShowImage("Pow", res)

cv.Max(im, im2, res)  #Maximum between two pixels
#Same form Min MinS
cv.ShowImage("Max", res)

cv.WaitKey(0)