コード例 #1
0
    def _detect(self,im):
        '''
        void cvCornerHarris( const CvArr* image, CvArr* harris_responce, int block_size, int aperture_size=3, double k=0.04 );
        '''
        gray = im.asOpenCVBW()
        #gray = opencv.cvCreateImage( opencv.cvGetSize(cvim), 8, 1 );
        corners = cv.CreateImage( cv.GetSize(gray), 32, 1 );
        #opencv.cvCvtColor( cvim, gray, opencv.CV_BGR2GRAY );
    
        cv.CornerHarris(gray,corners,self.block_size,self.aperture_size,self.k)

        data_buffer = corners.tostring()
        corners = np.frombuffer(data_buffer,np.float32).reshape(corners.height,corners.width).transpose()        
        
        footprint = np.ones((3,3))
        mx = ndi.maximum_filter(corners, footprint = footprint)
        local_maxima = (corners == mx) * (corners != np.zeros(corners.shape)) # make sure to remove completly dark points

        points = np.nonzero(local_maxima)
        del local_maxima
        
        points = np.array([points[0],points[1]]).transpose()
        L = []
        for each in points:
            L.append((corners[each[0],each[1]],each[0],each[1],None))
        
        return L
コード例 #2
0
def corner_detection(image):
    img_or = cv.LoadImage(image)
    img = cv.LoadImage(image, cv.CV_LOAD_IMAGE_GRAYSCALE)
    w = img.width
    h = img.height
    print w, h
    cornerMap = cv.CreateMat(h, w, cv.CV_32FC1)
    print cornerMap
    #Harris Corner Detection
    cv.CornerHarris(img, cornerMap, 3)

    corners = []
    #Recorriendo toda la imagen
    for x in range(0, h):
        for y in range(0, w):
            harris = cv.Get2D(cornerMap, x, y)
            #Validar la respuesta de deteccion de esquinas
            if harris[0] > 10e-06:
                #Dibujar un circulo en la imagen original
                cv.Circle(img_or, (y, x), 2, cv.RGB(155, 0, 25))
                corners.append([y, x])

    #Muestra la imagen y la guarda
    cv.ShowImage('Harris', img_or)
    cv.SaveImage('harris.jpg', img_or)
    cv.WaitKey()

    return corners, img
コード例 #3
0
    def processFrames(self):
        self.vidcap = cv2.VideoCapture(self.path)

        count = 0

        success, image = self.vidcap.read()
        print success

        self.createWindows()

        while True:
            success, image = self.vidcap.read()

            if not success:
                return

            spare = cv.fromarray(image)

            size = (spare.width / 2, spare.height / 2)

            cv.Smooth(spare, spare, cv.CV_GAUSSIAN, BLUR_SIZE, BLUR_SIZE)

            out = cv.CreateImage(size, 8, 3)
            cv.PyrDown(spare, out)

            yuv = cv.CreateImage(size, 8, 3)
            gray = cv.CreateImage(size, 8, 1)
            canny = cv.CreateImage(size, 8, 1)
            sobel = cv.CreateImage(size, 8, 1)
            harris = cv.CreateImage(size, cv.IPL_DEPTH_32F, 1)

            cv.CvtColor(out, yuv, cv.CV_BGR2YCrCb)
            cv.Split(yuv, gray, None, None, None)

            cv.Canny(gray, canny, 50, 200, 3)
            cv.CornerHarris(gray, harris, 3)
            cv.Sobel(gray, sobel, 1, 0, 3)

            cv.ConvertScale(canny, canny, -1, 255)
            cv.ConvertScale(sobel, sobel, -1, 255)

            for y in range(0, out.height):
                for x in range(0, out.width):
                    harr = cv.Get2D(sobel, y, x)
                    if harr[0] < 10e-06:
                        cv.Circle(out, (x, y), 2, cv.RGB(155, 0, 25))

            #cv2.imwrite("frame%d.jpg" % count, np.asarray(canny[:,:]))

            cv.ShowImage('canny', canny)
            #cv.ShowImage(   'harris'   , harris  )
            cv.ShowImage('sobel', sobel)
            cv.ShowImage('output', out)

            if cv2.waitKey(1) == 27:
                break
            count += 1

        return
コード例 #4
0
def getCornerMap(frame):
    global corner
    cornerMap = cv.CreateMat(frame.height, frame.width, cv.CV_32FC1)
    if (corner < 1):
        corner = 1
        cv.SetTrackbarPos("corner", "RGB module", 1)
    cv.CornerHarris(frame, cornerMap, corner)
    return (cornerMap)
コード例 #5
0
def detect_harris(array):
    image = as_ipl(array)
    cornerMap = cv.CreateMat(image.height, image.width, cv.CV_32FC1)
    cv.CornerHarris(image, cornerMap, 3)
    signature = np.zeros((image.height, image.width)).astype('uint8')
    for y in range(0, image.height):
        for x in range(0, image.width):
            harris = cv.Get2D(cornerMap, y, x)
            if harris[0] > 10e-06:
                cv.Circle(image,(x,y),1,cv.RGB(155, 0, 25), 3,8,0)
                signature[y, x] = 255
    corner_array = np.asarray(signature[:, :])
    return corner_array
コード例 #6
0
    imshow("Red channel", channelR)
    imshow("Green channel", channelG)
    imshow("Blue channel", channelB)

    # Show image in black and white and in colour.
    cv.ShowImage("Normal feed", imcolor)
    cv.ShowImage("Black and white", image)

    # Initialise the octagon
    octagon(imcolor)

    # *** GP: Destination of the harris algorithm
    cornerMap = cv.CreateMat(image.height, image.width, cv.CV_32FC1)

    # *** GP: OpenCV corner detection
    cv.CornerHarris(image, cornerMap, 3)

    # *** GP: Iterate through each pixel to get the final command.
    for y in range(0, image.height):
        for x in range(0, image.width):
            harris = cv.Get2D(cornerMap, y, x)  # get the x,y value

            # *** GP: check the corner detector response
            if harris[0] > 10e-06:

                # *** GP: draw a small circle on the original image to represent the corner
                # *** USER: change the colour of the detected corner.
                cv.Circle(imcolor, (x, y), 2, cv.RGB(155, 0, 25))

                # Check if it is in one of the 8 points.
                active(x, y)
コード例 #7
0
def harris():
    import cv
    import math
    global a
    imcolor = cv.LoadImage('leaf1.jpg')
    image = cv.LoadImage('leaf1.jpg', cv.CV_LOAD_IMAGE_GRAYSCALE)
    cornerMap = cv.CreateMat(image.height, image.width, cv.CV_32FC1)
    # OpenCV corner detection
    cv.CornerHarris(image, cornerMap, 3)

    pts = []
    print "one"
    for y in range(0, image.height):
        for x in range(0, image.width):
            harris = cv.Get2D(cornerMap, y, x)  # get the x,y value

            # check the corner detector response
            if harris[0] > 10e-06:
                ##   print x
                ##   print y
                # draw a small circle on the original image
                cv.Circle(imcolor, (x, y), 2, cv.RGB(155, 0, 25))
                pts.append((x, y))

    ang = []
    for i in range(1, len(pts) - 2):
        x1 = float(pts[i - 1][0])
        y1 = float(pts[i - 1][1])
        x2 = float(pts[i][0])
        y2 = float(pts[i][1])
        try:
            s1 = (y2 - y1) / (x2 - x1)
        except:
            pass

        x1 = float(pts[i][0])
        y1 = float(pts[i][1])
        x2 = float(pts[i + 1][0])
        y2 = float(pts[i + 1][1])
        try:
            s2 = (y2 - y1) / (x2 - x1)
        except:
            pass

        ang.append(abs(math.atan(s2 - s1)))

    imcolor = cv.LoadImage(a)
    image = cv.LoadImage(a, cv.CV_LOAD_IMAGE_GRAYSCALE)
    cornerMap = cv.CreateMat(image.height, image.width, cv.CV_32FC1)
    # OpenCV corner detection
    cv.CornerHarris(image, cornerMap, 3)

    pts = []
    print "one"
    for y in range(0, image.height):
        for x in range(0, image.width):
            harris = cv.Get2D(cornerMap, y, x)  # get the x,y value

            # check the corner detector response
            if harris[0] > 10e-06:
                ##   print x
                ##   print y
                # draw a small circle on the original image
                cv.Circle(imcolor, (x, y), 2, cv.RGB(155, 0, 25))
                pts.append((x, y))

    ang1 = []
    for i in range(1, len(pts) - 2):
        x1 = float(pts[i - 1][0])
        y1 = float(pts[i - 1][1])
        x2 = float(pts[i][0])
        y2 = float(pts[i][1])
        try:
            s1 = (y2 - y1) / (x2 - x1)
        except:
            pass

        x1 = float(pts[i][0])
        y1 = float(pts[i][1])
        x2 = float(pts[i + 1][0])
        y2 = float(pts[i + 1][1])
        try:
            s2 = (y2 - y1) / (x2 - x1)
        except:
            pass

        ang1.append(abs(math.atan(s2 - s1)))

    ind = min(len(ang), len(ang1))
    print ind

    val = 0
    for i in range(0, ind):
        val += ang[i] - ang1[i]

    print val
    if val <= 0:
        print 'images are similar...'
        exit()
    else:
        print "Different Images"
        exit()