def mouseImage(event, x, y, flags, param):
    """Handles incoming mouse input to the Image window."""
    
    if event==cv.CV_EVENT_LBUTTONDOWN:  #Clicked the left button
        print "x, y are", x, y
        (b,g,r) = D.image[y,x]
        print "r,g,b is", int(r), int(g), int(b)
        (h,s,v) = D.hsv[y,x]
        print "h,s,v is", int(h), int(s), int(v)
        D.down_coord = (x,y)
        D.mouse_down = True
        
    elif event==cv.CV_EVENT_LBUTTONUP:  #Let go of the left button
        print "x, y are", x, y
        (b,g,r) = D.image[y,x]
        print "r,g,b is", int(r), int(g), int(b)
        (h,s,v)  = D.hsv[y,x]
        print "h,s,v is", int(h), int(s), int(v)
        D.up_coord = (x,y)
        D.mouse_down = False

        if D.mode == "clear":
            D.sections = []
        else:      #Start, add, or subtract -- put lower coordinates first
            x0, y0, x1, y1 = D.down_coord[0], D.down_coord[1], D.up_coord[0], D.up_coord[1]

            if x0 > x1:
                x0, x1 = x1, x0
            if y0 > y1:
                y0, y1 = y1, y0
            
            if D.mode == "start":
                D.sections = []
            mode_dict = {"start":'a', "add":'a', "subtract":'s'}
            D.sections.append([mode_dict[D.mode], (x0, y0), (x1, y1)])
            ImageProcessing.process_section(D)


    elif event == cv.CV_EVENT_RBUTTONDOWN:                      #Right click
        D.target_coord = (x, y)
        ImageProcessing.target_coord(D)


    elif D.mouse_down and event==cv.CV_EVENT_MOUSEMOVE:      #Mouse just moved
        D.up_coord = (x,y)
def handle_image_data(data):
    """Handles incoming RGB image data from the Kinect."""
    
    #Get the incoming RGB image from the Kinect
    D.image = D.bridge.imgmsg_to_cv(data, "bgr8")

    if D.created_images == False:
        #Initialize the additional images we need for processing
        ImageProcessing.initialize(D)
        D.created_images = True

    # Recalculate threshold image
    ImageProcessing.threshold_image(D)

    # Recalculate blob in main image
    ImageProcessing.find_biggest_region(D)

    # Check on the display of dragged section
    ImageProcessing.mouse_section(D)

    #Display target circle
    #ImageProcessing.target_coord(D)
    
    #Display info box on image
    ImageProcessing.draw_on_image(D)
    
    #Handle incoming key presses
    key_press = cv.WaitKey(5) & 255
    if key_press != 255:			#Handle only if it's a real key
        check_key_press(D, key_press)		#(255 = "no key pressed")

    #Update the displays:
    #Show main image in the image window
    cv.ShowImage('Image', D.image)

    #Show threshold image in the threshold window
    currentThreshold = getattr(D, D.current_threshold)
    cv.ShowImage('Threshold', currentThreshold)
Beispiel #3
0
    
    correct_circles = (('OnWater1.jpg',((520,312,100),)),('OnDeck.jpg',((731,416,106),))
        ,('TwoBalls.jpg',((519,308,106),(1534,312,106))))
    circle_comparisons = []
    num_balls = 0
    for file_name,measur_circle in correct_circles:
        #Keep track of the number of balls measured
        num_balls+= len(measur_circle)   
        
        image = InputOutput.get_image(file_name)
        InputOutput.display_image(image,"Starting Image")

        image_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # convert to HSV for thresholding
        image_hsv = cv2.blur(image_hsv, (9,9)) # blur to reduce noise
 
        thresh = ImageProcessing.thresholdRed(image_hsv)
        InputOutput.display_image(thresh,"Thresholded")
        thresh = ImageProcessing.removeNoise(thresh)    
    
        #calc_circles = ImageProcessing.houghTransform(thresh)
        calc_circles = ImageProcessing.blob_circle_detection(thresh)
        if calc_circles == None:
            calc_circles = []
        #calc_circles = ImageProcessing.get_blob_centroid(image, thresh, 5)
         
        InputOutput.display_image_with_circles(image,"Result!",calc_circles)
        
        #evalueateSuccess by comparing the circle position with the most similar
        #red ball's measured circle.
        
        #Print basic file facts
Beispiel #4
0
import numpy as np
import cv2

import ImageProcessing

handImg = cv2.imread("../data/hand.png")
eyeImg = cv2.imread("../data/eye.png")
maskImg = cv2.imread("../data/mask.png")

#zmiana obrazka kolorowego na obrazek w skali szarosci
mask = np.mean(maskImg, axis=2)

eyeImg = ImageProcessing.colorTransfer(handImg, eyeImg, mask)
blendedImg = ImageProcessing.blendImages(eyeImg, handImg, mask)

cv2.imwrite("../eyeHandBlend.jpg", blendedImg)
Beispiel #5
0
    if shapes2D is not None:
        for shape2D in shapes2D:
            #3D model parameter initialization
            modelParams = projectionModel.getInitialParameters(mean3DShape[:, idxs3D], shape2D[:, idxs2D])

            #3D model parameter optimization
            modelParams = NonLinearLeastSquares.GaussNewton(modelParams, projectionModel.residual, projectionModel.jacobian, ([mean3DShape[:, idxs3D], blendshapes[:, :, idxs3D]], shape2D[:, idxs2D]), verbose=0)

            #rendering the model to an image
            shape3D = utils.getShape3D(mean3DShape, blendshapes, modelParams)
            renderedImg = renderer.render(shape3D)

            #blending of the rendered face with the image
            mask = np.copy(renderedImg[:, :, 0])
            renderedImg = ImageProcessing.colorTransfer(cameraImg, renderedImg, mask)
            cameraImg = ImageProcessing.blendImages(renderedImg, cameraImg, mask)
       

            #drawing of the mesh and keypoints
            if drawOverlay:
                drawPoints(cameraImg, shape2D.T)
                drawProjectedShape(cameraImg, [mean3DShape, blendshapes], projectionModel, mesh, modelParams, lockedTranslation)

    if writer is not None:
        writer.write(cameraImg)

    cv2.imshow('image', cameraImg)
    key = cv2.waitKey(1)

    if key == 27: