Esempio n. 1
0
def thresholding(x):
    global thres, value, maxValue, img, tipo
    imgO = img
    if (x == 0):
        thres = None
        filtro = img
        value = 0
        maxValue = 255
        cv2.createTrackbar('Value', windowTitle, value, maxValue, fValue)
        cv2.createTrackbar('MaxValue', windowTitle, maxValue, maxValue, fMaxValue)


    elif (x == 1):
        thres = cv2.THRESH_BINARY+cv2.THRESH_OTSU
    elif (x==2):
        thres = cv2.THRESH_BINARY+cv2.THRESH_OTSU
        img  = cv2.GaussianBlur(img,(5,5),0)
    if (x != 0):
        ret, filtro = cv2.threshold(img,value, maxValue, thres)
    tipo = x
    img = imgO
    blobImg = Image(filtro)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, filtro)
Esempio n. 2
0
def adaptative_thresholding(x):
    global thres, na, cons, maxValue, tipo, img, windoTitle
    if x == 0:
        thres = img
        maxValue = 255
        na = 11
        cons = 2;
        cv2.createTrackbar('Neighbourhood area (odds)', windowTitle, na, maxValue, fneighbourdhood_area)
        cv2.createTrackbar('Constant', windowTitle, -maxValue, maxValue, fConstant)
        cv2.createTrackbar('MaxValue', windowTitle, maxValue, maxValue, fMaxValue)
    elif x == 1:
        thres = cv2.adaptiveThreshold(img, maxValue,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, na, cons)
    elif x == 2:
        thres = cv2.adaptiveThreshold(img, maxValue, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,na,cons)
    tipo = x
    blobImg = Image(thres)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, thres)
Esempio n. 3
0
def fneighbourdhood_area(x):
    global na, thres, windowTitle, tipo
    if x % 2 ==0:
        na = x+1
    else:
        na = x
    if na == 0 or na == 1:
        na = 3
    if tipo == 0:
        thres = img
    elif tipo == 1:
        thres = cv2.adaptiveThreshold(img, maxValue,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, na, cons)
    elif tipo == 2:
        thres = cv2.adaptiveThreshold(img, maxValue, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,na,cons)
    blobImg = Image(thres)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    
    cv2.imshow(windowTitle, thres)
Esempio n. 4
0
 def getSimpleCVImage(self):
     """Grabs a frame from the camera and returns a SimpleCV image object."""
     img = np.empty((self.vRes * self.hRes * 3), dtype=np.uint8)
     self.picam.capture(img, 'bgr', use_video_port=True)
     img = img.reshape((self.vRes, self.hRes, 3))
     img = Image(img, colorSpace=ColorSpace.RGB)
     img = img.rotate90()
     img = img.flipVertical()
     return img
Esempio n. 5
0
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
Esempio n. 6
0
def fMaxValue(x):
    global maxValue, value, thres, img, filtro
    maxValue = x
    if (thres is None):
        filtro = img

    else:
        ret, filtro = cv2.threshold(img,value, maxValue, thres)
    blobImg = Image(filtro)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, filtro)
Esempio n. 7
0
def fMaxValue(x):
    global maxValueAdaptative, windowTitle, thresAdaptative, img, naAdaptative, consAdaptative, filtro
    maxValueAdaptative = x
    if tipoAdaptative == 0:
        thresAdaptative = img
    elif tipoAdaptative == 1:
        thresAdaptative = cv2.adaptiveThreshold(filtro, maxValueAdaptative,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, naAdaptative, consAdaptative)
    elif tipoAdaptative == 2:
        thresAdaptative = cv2.adaptiveThreshold(filtro, maxValueAdaptative, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,naAdaptative,consAdaptative)
    blobImg = Image(thresAdaptative)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, thresAdaptative)
Esempio n. 8
0
def fConstant(x):
    global cons, thres, windowTitle, tipo, maxValue, na, img
    # const positive to white, otherwise, to black
    cons = x
    if tipo == 0:
        thres = img
    elif tipo == 1:
        thres = cv2.adaptiveThreshold(img, maxValue,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, na, cons)
    elif tipo == 2:
        thres = cv2.adaptiveThreshold(img, maxValue, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,na,cons)
    
    blobImg = Image(thres)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, thres)
Esempio n. 9
0
def thresholding(x):
    global thres, value, maxValue, img, filtro
    if (x == 0):
        thres = None
        filtro = img
        value = 127
        maxValue = 255
        cv2.createTrackbar('Value', windowThres, value, maxValue, fValue)
        cv2.createTrackbar('MaxValue', windowThres, maxValue, maxValue, fMaxValue)

    elif (x == 1):
        thres = cv2.THRESH_BINARY
    elif (x==2):
        thres = cv2.THRESH_BINARY_INV

    elif (x==3):
        thres = cv2.THRESH_TRUNC

    elif (x==4):
        thres = cv2.THRESH_TOZERO

    elif (x==5):
        thres = cv2.THRESH_TOZERO_INV
    if (x != 0):
        ret, filtro = cv2.threshold(img,value, maxValue, thres)
    blobImg = Image(filtro)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, filtro)
    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
Esempio n. 11
0
from SimpleCV import Image
import cv2

__author = "mimadrid"

#img = Image('edi uveitis previa 11.png')
windowTitle = "canny detector"
cv2_img = cv2.imread('edi uveitis final6.png')
scv_img = Image(cv2_img, cv2image=True)
scv_img = scv_img.rotate90()

def threshold(value):
    global scv_img
    # The t1 parameter is roughly the "strength" of the edge required, and the
    # value between t1 and t2 is used for edge linking.  
    output = scv_img.edges(t1=value)
    #output.show()
    cv2.imshow(windowTitle, output.getNumpyCv2())


if __name__ == "__main__":
    cv2.namedWindow(windowTitle, cv2.WINDOW_NORMAL)
    cv2.createTrackbar('Threshold', windowTitle, 0, 1000, threshold)
    #output.show()
    #imgs.addDrawingLayer(output.dl())    
    #cv2_image = scv_img.getNumpyCv2()
    #ocv_gray = cv2.cvtColor(ocv_image, cv2.cv.CV_BGR2GRAY)
    cv2.imshow(windowTitle, scv_img.getNumpyCv2())
    while True:

        # key = cv2.waitKey(0)