Ejemplo n.º 1
0
def display_tracking(img_size, img1, img2, img_flow, homography):
    for x in range(0, img_size[0], 100):
        for y in range(0, img_size[1], 100):
            cv.Circle(img1, (x, y), 3, (0, 255, 0, 0), -1, 8, 0)
            point = cv.CreateMat(3, 1, cv.CV_64F)
            point[0, 0] = x
            point[1, 0] = y
            point[2, 0] = 1
            newpoint = cv.CreateMat(3, 1, cv.CV_64F)
            cv.MatMul(homography, point, newpoint)
            cv.Circle(img2, (int(newpoint[0, 0]), int(newpoint[1, 0])), 3,
                      (0, 255, 0, 0), -1, 8, 0)
            cv.Line(img_flow, (x, y),
                    (int(newpoint[0, 0]), int(newpoint[1, 0])),
                    cv.CV_RGB(255, 0, 0), 2)
    cv.Rectangle(img_flow, (0, 0), (150, 25), cv.CV_RGB(0, 0, 0), thickness=-1)
    cv.PutText(
        img_flow, "Good?: " + str(isHomographyGood(homography)), (0, 20),
        cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.75, 0.75, thickness=2),
        cv.CV_RGB(255, 255, 255))
    cv.NamedWindow("Image1", 0)
    cv.NamedWindow("Image2", 0)
    cv.NamedWindow("Flow", 0)
    cv.ResizeWindow("Image1", int(0.5 * img_size[0]), int(0.5 * img_size[1]))
    cv.ResizeWindow("Image2", int(0.5 * img_size[0]), int(0.5 * img_size[1]))
    cv.ResizeWindow("Flow", int(0.5 * img_size[0]), int(0.5 * img_size[1]))
    cv.ShowImage("Image1", img1)
    cv.ShowImage("Image2", img2)
    cv.ShowImage("Flow", img_flow)
    cv.WaitKey(0)
Ejemplo n.º 2
0
    def process(self, gui):
        """Process file, find corners on chessboard and keep points
        """
        gui.setMessage("Analyzing movie... get frame count")
        
        #open capture file
        capture = cv.CaptureFromFile(self.filename)
        frame = cv.QueryFrame(capture)
        
        #count... I know it sucks
        numframes=1
        while frame:
            frame = cv.QueryFrame(capture)
            numframes +=1

        step = int(numframes/Calibration.NUMPOINT)
        capture = cv.CaptureFromFile(self.filename)
        frame = cv.QueryFrame(capture) #grab a frame to get some information
        self.framesize = (frame.width, frame.height)
        gray = cv.CreateImage((frame.width,frame.height), 8, 1)

        points = []
        nframe = 0
        f=0
        cv.NamedWindow("ChessBoard",cv.CV_WINDOW_NORMAL)

        gui.setMessage("Analyzing movie... find chessCorner for %d frames" % Calibration.NUMPOINT)

        while frame:
            f+=1    
            #find corners
            state,found = cv.FindChessboardCorners(frame, self.chessSize, flags=cv.CV_CALIB_CB_FILTER_QUADS)
            if state==1:
                #affine search
                cv.CvtColor( frame, gray, cv.CV_BGR2GRAY )
                found = cv.FindCornerSubPix(gray, found, (11,11), (-1,-1), (cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS, 30, 0.1))

                #draw corners on image
                cv.DrawChessboardCorners(frame, self.chessSize, found, state)
                #compute points 
                for x,y in found:
                    points.append((x,y))
                nframe+=1

            cv.ResizeWindow("ChessBoard",640,480)
            cv.ShowImage("ChessBoard",frame)

            cv.WaitKey(4)
            frame = cv.QueryFrame(capture) #grab a frame to get some information

            #skip frames to get only NUMPOINT of point to calculate
            while f%step != 0 and frame:
                f+=1
                frame = cv.QueryFrame(capture)

        self.points = points
        self.nframe = nframe

        gui.setMessage("Analyze end, %d points found" % len(self.points))
Ejemplo n.º 3
0
def show_rotated():
    g = main.grid.occ
    #g = blockcraft.centered_rotated(main.R_correct, g)
    g = blockcraft.translated_rotated(main.R_correct, g)
    marginal = g.sum(1).astype('u1') * 255
    cv.NamedWindow('scale_test', 0)
    cv.ShowImage('scale_test', cv.fromarray(marginal))
    cv.ResizeWindow('scale_test', 300, 300)
Ejemplo n.º 4
0
    def __init__(self, node_name):
        rospy.init_node(node_name)

        rospy.on_shutdown(self.cleanup)

        self.node_name = node_name
        self.input_rgb_image = "input_rgb_image"
        self.input_depth_image = "input_depth_image"
        self.output_image = "output_image"
        self.show_text = rospy.get_param("~show_text", True)
        self.show_features = rospy.get_param("~show_features", True)
        """ Initialize the Region of Interest and its publisher """
        #self.ROI = RegionOfInterest()
        #self.pubROI = rospy.Publisher("/roi", RegionOfInterest)
        """ Do the same for the point cluster publisher """
        #self.cluster3d = PointStamped()
        #self.pub_cluster3d = rospy.Publisher("/target_point", PointStamped)
        """ Initialize a number of global variables """
        self.image = None
        self.image_size = None
        self.depth_image = None
        self.grey = None
        self.selected_point = None
        self.selection = None
        self.drag_start = None
        self.keystroke = None
        self.key_command = None
        self.detect_box = None
        self.track_box = None
        self.display_box = None
        self.keep_marker_history = False
        self.night_mode = False
        self.auto_face_tracking = True
        self.cps = 0  # Cycles per second = number of processing loops per second.
        self.cps_values = list()
        self.cps_n_values = 20
        self.flip_image = False
        """ Create the display window """
        self.cv_window_name = self.node_name
        cv.NamedWindow(self.cv_window_name, cv.CV_NORMAL)
        cv.ResizeWindow(self.cv_window_name, 640, 480)
        """ Create the cv_bridge object """
        self.bridge = CvBridge()
        """ Set a call back on mouse clicks on the image window """
        cv.SetMouseCallback(self.node_name, self.on_mouse_click, None)
        """ A publisher to output the display image back to a ROS topic """
        self.output_image_pub = rospy.Publisher(self.output_image, Image)
        """ Subscribe to the raw camera image topic and set the image processing callback """
        self.image_sub = rospy.Subscriber(self.input_rgb_image,
                                          Image,
                                          self.image_callback,
                                          queue_size=1)
        self.depth_sub = rospy.Subscriber(self.input_depth_image,
                                          Image,
                                          self.depth_callback,
                                          queue_size=1)

        rospy.loginfo("Starting " + self.node_name)
Ejemplo n.º 5
0
def FPV_thread():
    global camera_index
    global capture
    global WINDOW_NAME
    global latest_frame
    global FPV_thread_stop
    global overlay_message  # shared with application return results
    global face_position    # shared with application return results

    FPV_init()

    cv.NamedWindow(WINDOW_NAME, cv.CV_WINDOW_NORMAL)
    cv.MoveWindow(WINDOW_NAME, 0, 0)

    width_scale = 1.0
    height_scale = 1.0
    while True:
        frame = cv.QueryFrame(capture)
        cv.Flip(frame, None, 1)

        #copy to buffer
        frame_lock.acquire()
        original_imagesize = (0,0)
        resized_imagesize = (0,0)
        if not latest_frame:
            latest_frame = cv.CreateImage((640, 480), frame.depth, frame.nChannels)
            original_imagesize = cv.GetSize(frame)
            resized_imagesize = cv.GetSize(latest_frame)
            width_scale = original_imagesize[0]*1.0/resized_imagesize[0]
            height_scale = original_imagesize[1]*1.0/resized_imagesize[1]
        cv.Resize(frame, latest_frame)
        frame_lock.release()


        #Display Result
        text_start_point = (10, 50)
        cv.PutText(frame, overlay_message, text_start_point, font, cv.Scalar(255,255,255))
        cv.Rectangle(frame, text_start_point, (original_imagesize[0], 100), cv.Scalar(0,0,0), thickness=cv.CV_FILLED)
        if face_position[0] > 0.0:
            point1 = (int(face_position[0]*width_scale), int(face_position[1]*height_scale))
            point2 = (int((face_position[0] + face_position[2])*width_scale), \
                    int((face_position[1]+face_position[3])*height_scale))
            cv.Rectangle(frame, point1, point2, \
                    cv.Scalar(255, 255, 255), thickness=2)
        cv.ShowImage(WINDOW_NAME, frame)
        cv.ResizeWindow(WINDOW_NAME, 200, 100)
        cv.NamedWindow(WINDOW_NAME, cv.CV_WINDOW_NORMAL);
        cv.SetWindowProperty(WINDOW_NAME, 0, cv.CV_WINDOW_FULLSCREEN);
        c = cv.WaitKey(10)
        if c == ord('q'):
            break

    print "[INFO] FPV Thread is finished"
    FPV_thread_stop = True
    FPV_close()
Ejemplo n.º 6
0
def scan_receipt(file_name):
    image = cv.LoadImage(RECEIPT_PATH + file_name)
    if not image:
        print "Error opening image"
        sys.exit(1)

    cv.NamedWindow('output', cv.CV_WINDOW_NORMAL)
    cv.ShowImage('output', image)
    cv.ResizeWindow('output', 960, 640)
    cv.WaitKey()
    image2 = cv2.imread(RECEIPT_PATH + file_name)
    corners = detect_corners(image2)
Ejemplo n.º 7
0
def disparity(file1, file2):
    sc = cv.CreateStereoBMState(preset=cv.CV_STEREO_BM_BASIC,
                                numberOfDisparities=0)
    #sc2 = cv.CreateStereoGCState(16, 2)
    img1 = cv.LoadImage(file1, cv.CV_LOAD_IMAGE_GRAYSCALE)
    img2 = cv.LoadImage(file2, cv.CV_LOAD_IMAGE_GRAYSCALE)
    img_sz = cv.GetSize(img1)
    img_out = cv.CreateImage(img_sz, cv.IPL_DEPTH_32F, 1)
    img_out2 = cv.CreateImage(img_sz, cv.IPL_DEPTH_32F, 1)
    img_out3 = cv.CreateImage(img_sz, cv.IPL_DEPTH_32F, 1)
    cv.FindStereoCorrespondenceBM(img1, img2, img_out, sc)
    #cv.FindStereoCorrespondenceGC(img1, img2, img_out2, img_out3, sc2)
    cv.NamedWindow("Image1", 0)
    cv.NamedWindow("Image2", 0)
    cv.NamedWindow("Disparity", 0)
    cv.ResizeWindow("Image1", int(0.5 * img_sz[0]), int(0.5 * img_sz[1]))
    cv.ResizeWindow("Image2", int(0.5 * img_sz[0]), int(0.5 * img_sz[1]))
    cv.ResizeWindow("Disparity", int(0.5 * img_sz[0]), int(0.5 * img_sz[1]))
    cv.ShowImage("Image1", img1)
    cv.ShowImage("Image2", img2)
    cv.ShowImage("Disparity", img_out)
    cv.WaitKey(0)
Ejemplo n.º 8
0
    def undistort(self, gui, cam, dist):
        """Undistort file
        """
        gui.setMessage("Undistort movie... get frame count")

        #open capture file
        capture = cv.CaptureFromFile(self.filename)
        frame = cv.QueryFrame(capture)
        
        #count... I know it sucks
        numframes=1
        while frame:
            frame = cv.QueryFrame(capture)
            numframes +=1

        capture = cv.CaptureFromFile(self.filename)
        frame = cv.QueryFrame(capture) #grab a frame to get some information
        self.framesize = (frame.width, frame.height)
        gray = cv.CreateImage((frame.width,frame.height), 8, 1)
        undistorted_frame = cv.CreateImage((frame.width,frame.height), 8, 3)

        cv.NamedWindow("Uncalibrated image",cv.CV_WINDOW_NORMAL)
        cv.NamedWindow("Calibrated image",cv.CV_WINDOW_NORMAL)

        while frame:
            cv.Undistort2(frame, undistorted_frame, cam, dist)

            cv.ResizeWindow("Uncalibrated image",640,480)
            cv.ResizeWindow("Calibrated image",640,480)
            cv.ShowImage("Calibrated image",undistorted_frame)
            cv.ShowImage("Uncalibrated image",frame)

            cv.WaitKey(0)
            frame = cv.QueryFrame(capture) #grab a frame to get some information

        self.points = points
        self.nframe = nframe

        gui.setMessage("Analyze end, %d points found" % len(self.points))
Ejemplo n.º 9
0
    def __init__(self, cModel):
        self.model = cModel
        windowName = "Fisheye"
        cv.NamedWindow(windowName,cv.CV_WINDOW_NORMAL)
        cv.NamedWindow('Image')
        cv.MoveWindow('Image',1,220)
        x,y = self.model.res

        cv.CreateTrackbar ("Threshold", windowName, 1, 100,
                self.onThresholdChange)
        cv.CreateTrackbar ("Horizon", windowName, 10,
                min(self.model.res)/2, self.onRadiusChange)
        cv.CreateTrackbar ("North", windowName, 90, 360, self.onNorthChange)
        cv.CreateTrackbar ('x', windowName, x/2, x, self.on_Xchange)
        cv.CreateTrackbar ('y', windowName, y/2, y, self.on_Ychange)
        cv.ResizeWindow(windowName, 1200,200)
        self.onThresholdChange (0)
Ejemplo n.º 10
0
    def __init__(self, name, x=None, y=None, w=None, h=None):
        """ Create OpenCV Window.
            - Auto-resize if now size is given.
            - Auto-position to 0x0 if no pos given
        """

        if w is not None and h is not None:
            cv.NamedWindow(name, 0)
            cv.ResizeWindow(name, w, h)
        else:
            cv.NamedWindow(name, cv.CV_WINDOW_AUTOSIZE)

        if x is not None and y is not None:
            cv.MoveWindow(name, x, y)

        self.name = name
        self.settings = {}
Ejemplo n.º 11
0
    def nextFrame(self):
        frame = self.video.fetch(self.channel)
        mode = self.video.outputMode(self.channel)
        if frame == None: return False

        frame = (frame * 255.0).astype(numpy.uint8)
        if mode == MODE_RGB:
            out = array2cv(frame[:, :, ::-1])
        elif mode == MODE_FLOAT:
            out = array2cv(frame)
        else:
            raise Exception('Unsuported mode for WriteCV')

        cv.ResizeWindow(self.title, frame.shape[1], frame.shape[0])
        cv.ShowImage(self.title, out)

        return True
Ejemplo n.º 12
0
    def show_faces(self, mytime=1000):
        """
        Show all faces that have been found for the guys.
        The time for which each image will be displayed can be chosen.

        :param mytime: time for which the image should be displayed (in ms) (1000)
        :type mytime: int
        """
        win_name = " Face Results"
        cv.NamedWindow(win_name, cv.CV_WINDOW_NORMAL)
        cv.ResizeWindow(win_name, 640, 480)

        for a_guy in self.guys:
            if self.run:
                out_im = self.prepare_image(a_guy)
                cv.ShowImage(win_name, out_im)
                cv.WaitKey(mytime)

        cv.DestroyWindow(win_name)
Ejemplo n.º 13
0
def analyze_webcam(width, height):
    print("""
    ' ' : extract colors of detected face
    'b' : toggle onlyBlackCubes
    'd' : toggle dodetection
    'm' : shift right
    'n' : shift left
    'r' : reset everything
    'q' : print hsvs
    'p' : resolve colors
    'u' : toggle didassignments
    's' : save image
""")

    # 0 for laptop camera
    # 1 for usb camera
    capture = cv.CreateCameraCapture(0)

    # Set the capture resolution
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, width)
    cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, height)

    # Create the window and set the size to match the capture resolution
    cv.NamedWindow("Fig", cv.CV_WINDOW_NORMAL)
    cv.ResizeWindow("Fig", width, height)

    frame = cv.QueryFrame(capture)
    rf = RubiksFinder(width, height)

    while True:
        frame = cv.QueryFrame(capture)

        if not frame:
            cv.WaitKey(0)
            break

        rf.analyze_frame(frame)

        if not rf.process_keyboard_input():
            break

    cv.DestroyWindow("Fig")
Ejemplo n.º 14
0
    def detect(self):
        """
        project images, take and process pictures to get projector pixel to 
        camera pixel mappings.
        """
        cv.NamedWindow(windowtitle, cv.CV_WINDOW_NORMAL)
        cv.ResizeWindow(windowtitle, self.screenSize[0], self.screenSize[1])
        cv.SetWindowProperty(windowtitle, 0, cv.CV_WINDOW_FULLSCREEN)
        cv2.imshow(windowtitle, self.projector_image)
        cv2.waitKey(500)
        self.dark_baseline = self.takeSnapshot()

        # light up only everything that's within the current projector's
        # part of the projected image.
        self.projector_image[:] = 0
        self.viewport[:] = .3
        cv2.imshow(windowtitle, self.projector_image)
        cv2.waitKey(500)
        allpixels = self.takeSnapshot()
        self.bright_baseline = allpixels - self.dark_baseline
        cv2.imwrite('/tmp/allpixels.png', allpixels)
        self.mask = self.bright_baseline > 30
        cv2.imwrite('/tmp/mask.png', self.mask * 250.)

        self.projector_image[:] = 0

        if self.mask.any():
            for step, im in enumerate(self.imageIterator.generator()):
                self.viewport[:] = im
                cv2.imshow(windowtitle, self.projector_image)
                cv2.waitKey(500)
                image = self.takeSnapshot()
                self.handleImage(step, image)
            self.postProcess()
        else:
            logger.info(
                "No visible pixels. Skipping detection for this camera pose and projector."
            )
Ejemplo n.º 15
0
    def out_display(self, im, name, time=1000, im_x=640, im_y=480):
        """
        Displays the output image, for time ms.
        Setting time to 0 causes the image to remains open.
        Window name slightly changed to match output

        :param im: the image to be saved, formatted as an OpenCV Image
        :type im: IplImage
        :param name: the name of the image to be saved
        :type name: string

        :param time: time for which the image should be displayed (in ms) (1000)
        :type time: int
        :param im_x: output size of the displayed image (in pixels) (640)
        :type im_x: int
        :param im_y: output size of the displayed image (in pixels) (480)
        :type im_y: int
        """
        win_name = name + " - out"
        cv.NamedWindow(win_name, cv.CV_WINDOW_NORMAL)
        cv.ResizeWindow(win_name, im_x, im_y)
        cv.ShowImage(win_name, im)
        cv.WaitKey(time)
        cv.DestroyWindow(win_name)
Ejemplo n.º 16
0
  #This is the setup
  datalog = open("data.log", "w+")
  datalog.write("\n~~~=== Rambler Data Log Opened, " + str(datetime.now()) + " ===~~~\n")

  capture = cv.CaptureFromCAM(0)
  #capture = cv.CaptureFromFile("../out2.mpg")
  cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 320)
  cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 240)

  polar = cv.CreateImage((360, 360), 8, 3)
  unwrapped = cv.CreateImage((360, 40), 8, 3)
  cam = cv.CreateImage((320, 240), 8, 3)
  cones = cv.CreateImage((360, 40), 8, 1)

  cv.NamedWindow('cam')
  cv.ResizeWindow('cam', 320,240)
  cv.NamedWindow('unwrapped')
  cv.ResizeWindow('unwrapped', 360,40)
  cv.NamedWindow('cones')
  cv.ResizeWindow('cones', 360,40)

  sleep(3)
  cam = cv.QueryFrame(capture)
  sleep(3)
  cam = cv.QueryFrame(capture)
  sleep(3)
  cv.ShowImage('cam', cam)

  ##GUI #Enable these lines to allow mouse interaction with the polar transform
  ##GUI cv.SetMouseCallback('cam', on_mouse)
  cv.SetMouseCallback('unwrapped', on_mouse)
Ejemplo n.º 17
0
 def update(self):
     """Updates the window with the rendered image."""
     im = self.render()
     size = cv.GetSize(im)
     cv.ShowImage(self.title, im)
     cv.ResizeWindow(self.title, size[0], size[1] + len(self.args) * 35)
Ejemplo n.º 18
0
def create_and_position_window(name, xpos, ypos):
    ''' a function to created a named widow (from name), 
        and place it on the screen at (xpos, ypos) '''
    cv.NamedWindow(name, 1)
    cv.ResizeWindow(name, cam_width, cam_height)  # resize it
    cv.MoveWindow(name, xpos, ypos)  # move it to (xpos,ypos) on the screen
Ejemplo n.º 19
0
    y = (grid[2][0] + grid[2][1] * 2 + grid[2][2] * 4 + grid[2][3] * 8 +
         grid[2][4] * 16 + grid[3][0] * 32 + grid[3][1] * 64 +
         grid[3][2] * 128 + grid[3][3] * 256) * (grid[3][4] * -1)
    sector = grid[4][0] + grid[4][1] * 2 + grid[4][2] * 4
    direction = grid[4][3] + grid[4][4] * 2
    print 'X:', x
    print 'Y:', y
    print 'Sector:', sector
    print 'Direction:', direction


#loads image from a file and checks for glyphs in it
if __name__ == "__main__":

    if len(sys.argv) != 2:
        print "Please supply a file name"
        sys.exit()

    cv.NamedWindow('Glpyh Recognition', 0)

    image = cv.LoadImage("../images/" + sys.argv[1],
                         cv.CV_LOAD_IMAGE_COLOR)  #Load the image
    cv.ResizeWindow('source', 600, 800)

    grid = glyphRec(image)

    cv.ShowImage('Glpyh Recognition', image)

    while True:
        cv.WaitKey(1)
Ejemplo n.º 20
0
def findBlobs(img, min_color, max_color, originalwindow, renderedwindow,
              location, area, ratio):
    blobs = cvblob.Blobs()  #creates a dictionary of blobs
    size = cv.GetSize(img)  #gets size of image

    hsv = cv.CreateImage(size, cv.IPL_DEPTH_8U, 3)  #New HSV image for alter
    thresh = cv.CreateImage(size, cv.IPL_DEPTH_8U,
                            1)  #New Gray Image for later
    labelImg = cv.CreateImage(size, cvblob.IPL_DEPTH_LABEL,
                              1)  #New Blob image for later

    cv.CvtColor(img, hsv, cv.CV_BGR2HSV)  #converts image to hsv image
    cv.InRangeS(hsv, min_color, max_color, thresh)  #thresholds it

    #Corrections to remove false positives
    cv.Smooth(thresh, thresh, cv.CV_BLUR)
    cv.Dilate(thresh, thresh)
    cv.Erode(thresh, thresh)

    result = cvblob.Label(thresh, labelImg,
                          blobs)  #extracts blobs from a greyscale image

    numblobs = len(
        blobs.keys())  #number of blobs based off of length of blobs dictionary

    #if there are blobs found
    if (numblobs > 0):
        avgsize = int(result / numblobs)
        print str(numblobs) + " blobs found covering " + str(result) + "px"

        #Removes blobs that are smaller than a certain size based off of average size
        remv = []
        for x in blobs:
            if (blobs[x].area < avgsize / ratio):
                remv.append(x)
        for x in remv:
            del blobs[x]

        numblobs = len(
            blobs.keys())  #gets the number of blobs again after removing some
        print str(numblobs) + " blobs remaining"

        filtered = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_8U, 1)
        cvblob.FilterLabels(
            labelImg, filtered, blobs
        )  #Creates a binary image with the blobs formed (imgIn, imgOut, blobs)

        #Centroid, area, and circle for all blobs
        for blob in blobs:
            location.append(cvblob.Centroid(blobs[blob]))
            area.append(blobs[blob].area)
            cv.Circle(img, (int(cvblob.Centroid(
                blobs[blob])[0]), int(cvblob.Centroid(blobs[blob])[1])),
                      int(math.sqrt(int(blobs[blob].area) / 3.14)) + 25,
                      cv.Scalar(0, 0, 0))

        imgOut = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_8U, 3)
        cv.Zero(imgOut)

        cvblob.RenderBlobs(
            labelImg, blobs, img, imgOut,
            cvblob.CV_BLOB_RENDER_COLOR | cvblob.CV_BLOB_RENDER_CENTROID
            | cvblob.CV_BLOB_RENDER_BOUNDING_BOX | cvblob.CV_BLOB_RENDER_ANGLE,
            1.0)  #Marks up the blobs image to put bounding boxes, etc on it
        cv.ResizeWindow("Window", 640, 480)
        cv.ResizeWindow("Rendered", 640, 480)
        cv.ShowImage("Window", img)  #shows the orininalimage
        cv.ShowImage("Rendered", imgOut)  #shows the blobs image

        return blobs  #returns the list of blobs

    else:
        print " ...Zero blobs found. \nRedifine color range for better results"  #if no blobs were found print an error message
        cv.ResizeWindow("Window", 640, 480)
        cv.ResizeWindow("Rendered", 640, 480)
        cv.ShowImage("Window", img)  #show the original image
Ejemplo n.º 21
0
                saveCount += 1
                startCounter = False
                nSecond = 1 
                smileTime=True

    # Get user input
    keyPressed = GPIO.input(11)
    if keyPressed == ord('s'):
        print "start counter"
        startCounter = True
        startTime = datetime.now()
        keyPressTime = datetime.now()

    elif cv2.waitKey(3) == ord('q'):
        print "out"
        # Quit the while loop
        running = False
        cv2.destroyAllWindows()

    # Show video stream in a window    
    height, width = frame.shape[:2]
    scaleHeight = 750#int(round(1.3*width))
    scaleWidth = 800#int(round(1.3*height))
    res = cv2.resize(frame,(scaleWidth, scaleHeight), interpolation = cv2.INTER_CUBIC)
    cv2.imshow('video', res)

    cv.ResizeWindow('video', scaleWidth, scaleHeight+20)


camObj.release()
Ejemplo n.º 22
0
                          numpy.r_[2 * x[0] - x[window_len - 1::-1], x,
                                   2 * x[-1] - x[-1:-window_len:-1]],
                          mode='same')[window_len:-window_len + 1]


imagePath = sys.argv[1]

image = cv.LoadImage(imagePath)
cv_image = image  # I use this as a seperate canvas to draw on.

imageThreshold = cv.CreateImage(
    cv.GetSize(image), 8,
    1)  # The last number represents a binary image. It's the channel-depth.

cv.NamedWindow('Test', 0)
cv.ResizeWindow('Test', 1000, 600)

channelG = cv.CreateImage(
    cv.GetSize(image), 8,
    1)  # Initializes blank image holders for the channel separation.
channelB = cv.CreateImage(cv.GetSize(image), 8, 1)

cv.Split(
    image, cv.CreateImage(cv.GetSize(image), 8, 1), channelG, channelB, None
)  # Splits the input image into channels (RGB). I only use B and G because the laser is green, not red.

cv.Sub(
    channelG, channelB, imageThreshold
)  # Subtracts the channels. Since the green laser's pixels are basically have a G value of 255, they stand out. Uncomment the next two lines to see what I mean.
#cv.ShowImage('Test', imageThreshold)
#cv.WaitKey(0)
Ejemplo n.º 23
0
	def display(self):
		tmp = clone_image(self.img)
		overlay_text_on_image(tmp, "%s - %s" % (self.card_name, self.set_name), self.font)
		cv.ShowImage("match", tmp)
		cv.ResizeWindow("match", 800, 600)
Ejemplo n.º 24
0
                 help='separation distance')
    p.add_option('-s',
                 action='store_true',
                 dest='headless',
                 help='headless mode')
    opt, args = p.parse_args()

    cameras = [
        opt.cam + '/left/image_rect_color', opt.cam + '/right/image_rect_color'
    ]
    stereo_listener = rc.ROSStereoListener(cameras)
    if not opt.headless:
        #cv.NamedWindow('left', 0)
        #cv.NamedWindow('right', 0)
        cv.NamedWindow('stereo-anaglyph', 0)
        cv.ResizeWindow('stereo-anaglyph', 640, 480)
        cv.WaitKey(10)
    else:
        bridge = CvBridge()
        image_pub = rospy.Publisher('stereo_anaglyph', Image)

    anaglyph_cyan_image_distance_correction = rospy.get_param(
        'anaglyph_dist', opt.dist)

    left = 1113937  # 65361
    right = 1113939  #65363
    escape = 1048603  #27
    while not rospy.is_shutdown():
        l, r = stereo_listener.next()
        red_blue = anaglyph(l, r, anaglyph_cyan_image_distance_correction)
        if not opt.headless:
Ejemplo n.º 25
0
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', dest='config', default='config.yaml')
    args = parser.parse_args()

    import yaml
    config = yaml.load(open(args.config))
    stepsize = config['detection']['stepsize']
    screenSize = config['screen']['width'], config['screen']['height']
    cameraSize = config['camera']['width'], config['camera']['height']
    cam = instarCamera.instarCamera()

    blank_image = numpy.zeros((screenSize[1], screenSize[0]),
                              dtype=numpy.float)
    cv.NamedWindow(windowtitle, cv.CV_WINDOW_NORMAL)
    cv.ResizeWindow(windowtitle, screenSize[0], screenSize[1])
    cv.SetWindowProperty(windowtitle, 0, cv.CV_WINDOW_FULLSCREEN)
    cv2.imshow(windowtitle, blank_image)
    cv2.waitKey(50)

    data = []
    for shot in config['detection']['shots']:
        cam.rotateTo(shot['angles'])
        for projector in shot['projectors']:
            projectorConfig = config['projectors'][projector]
            projectorSize = projectorConfig['width'], projectorConfig['height']
            projectorOffset = projectorConfig['iOffset'], projectorConfig[
                'jOffset']
            detector = Detector(camera=cam,
                                screenSize=screenSize,
                                projectorSize=projectorSize,
Ejemplo n.º 26
0
    def __init__(self, node_name):
        rospy.init_node(node_name)

        rospy.on_shutdown(self.cleanup)

        self.node_name = node_name
        self.input_rgb_image = "input_rgb_image"
        self.input_depth_image = "input_depth_image"

        self.prevDepth = None

        self.pubFaceCloud = rospy.Publisher('gaze_cloud', PointCloud2)
        """ Initialize a number of global variables """
        self.image = None
        self.image_size = None
        self.depth_image = None
        self.grey = None
        self.small_image = None
        self.prev = None
        self.prev_img = None
        self.show_text = True
        self.prevFrameNum = 1

        self.mask = None
        """ Create the display window """
        self.cv_window_name = self.node_name
        cv.NamedWindow(self.cv_window_name, cv.CV_NORMAL)
        cv.ResizeWindow(self.cv_window_name, 640, 480)

        cv.NamedWindow('face box')
        """ Create the cv_bridge object """
        self.bridge = CvBridge()
        """ Set a call back on mouse clicks on the image window """
        cv.SetMouseCallback(self.node_name, self.on_mouse_click, None)
        """ Subscribe to the raw camera image topic and set the image processing callback """
        self.image_sub = rospy.Subscriber(self.input_rgb_image, Image,
                                          self.image_callback)
        self.depth_sub = rospy.Subscriber(self.input_depth_image, Image,
                                          self.depth_callback)

        #rospy.Subscriber("/camera/depth/image", Image, callback,
        #                 queue_size=1, callback_args=(pubFaceCloud,pubFaceNormals))
        #rospy.Subscriber("/roi", RegionOfInterest, callback,
        #                 queue_size=1, callback_args=(pubFaceCloud,pubFaceNormals))
        """ Set up the face detection parameters """
        self.cascade_frontal_alt = rospy.get_param("~cascade_frontal_alt", "")
        self.cascade_frontal_alt2 = rospy.get_param("~cascade_frontal_alt2",
                                                    "")
        self.cascade_profile = rospy.get_param("~cascade_profile", "")

        self.cascade_frontal_alt = cv.Load(self.cascade_frontal_alt)
        self.cascade_frontal_alt2 = cv.Load(self.cascade_frontal_alt2)
        self.cascade_profile = cv.Load(self.cascade_profile)

        self.camera_frame_id = "kinect_depth_optical_frame"

        self.depthFrameNum = 1

        self.drag_start = None
        self.selections = []

        # viola jones parameters
        self.min_size = (20, 20)
        self.image_scale = 2
        self.haar_scale = 1.5
        self.min_neighbors = 1
        self.haar_flags = cv.CV_HAAR_DO_CANNY_PRUNING

        self.seeds = None

        self.cps = 0  # Cycles per second = number of processing loops per second.
        self.cps_values = list()
        self.cps_n_values = 20

        self.featureFile = open(
            '/home/ben/Desktop/features/batch9_features.dat', 'w')
        self.clusters = [5, 4, 4, 3, 3, 5, 4, 3, 3][9 - 1]
        """ Wait until the image topics are ready before starting """
        rospy.wait_for_message(self.input_rgb_image, Image)
        rospy.wait_for_message(self.input_depth_image, Image)

        rospy.loginfo("Starting " + self.node_name)
Ejemplo n.º 27
0
def display(image):
    cv.NamedWindow("Red Eye Test", cv.CV_WINDOW_AUTOSIZE)
    cv.ResizeWindow("Red Eye Test", 10, 10)
    cv.ShowImage("Red Eye Test", image)
    cv.WaitKey(0)
    cv.DestroyWindow("Red Eye Test")
Ejemplo n.º 28
0
def analyze_file(filename):
    """
    Assuming filename is a png that contains a rubiks cube, return
    the RGB values for all 9 squares
    """
    img = cv.LoadImage(filename)

    (S1, S2) = cv.GetSize(img)
    rf = RubiksFinder(S1, S2)

    if display_window:
        cv.NamedWindow("Fig", cv.CV_WINDOW_NORMAL)
        cv.ResizeWindow("Fig", rf.width, rf.height)

    ATTEMPTS = 100
    rf.extract = True

    for x in xrange(ATTEMPTS):
        rf.analyze_frame(img)

        # we can "track" (find the cube in the pic) but it takes ~30 attempts...why ~30?
        log.info("analyze_frame %d/%d: tracking %s, THR %s" %
                 (x, ATTEMPTS - 1, rf.tracking, rf.THR))

        if rf.tracking:
            # log.warning("analyze_frame selected %s\ncolors\n%s\n\nhsvs\n%s\n\n" %
            #          (rf.selected,
            #           pformat(rf.colors),
            #           pformat(rf.hsvs)))

            if display_window:
                cv.ShowImage('foobar', img)
                cv.WaitKey(0)
            break
    else:
        raise Exception("Could not find the cube in %s" % filename)

    if display_window:
        cv.DestroyWindow("Fig")

    # When analyzing a file we are only examining one side so use index 0 for colors and center_pixels
    colors = rf.colors[0]
    center_pixels = rf.center_pixels[0]
    colors_final = []
    # log.warning("rf.colors\n %s" % pformat(rf.colors))
    # log.warning("rf.center_pixels\n%s" % pformat(rf.center_pixels))
    # log.warning("colors\n %s" % pformat(colors))
    # log.warning("center_pixels\n%s" % pformat(center_pixels))

    # opencv returns BGR, not RGB
    # http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.html#basic-ops
    for ((x, y), (blue, green, red, _)) in zip(center_pixels, colors):

        # Save in RGB, this makes the colors much easier to print on a web page
        # for troubleshooting, it is also the format expected by rubiks_rgb_solver.py
        colors_final.append({
            'x': x,
            'y': y,
            'red': int(red),
            'green': int(green),
            'blue': int(blue)
        })

    return colors_final
Ejemplo n.º 29
0
cascade_file_path = '/usr/local/share/opencv/haarcascades/'

cascade_files = [
    'haarcascade_frontalface_alt.xml',
    'haarcascade_mcs_eyepair_big.xml',
]

detector_names = [
    'face',
    'eyes',
]

font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, .75, .75, .12, 2)

cv.NamedWindow("Whole Image")
cv.ResizeWindow("Whole Image", *(640, 480))
cv.NamedWindow("ROI")
cv.ResizeWindow("ROI", *(200, 200))
cv.MoveWindow("ROI", *(640, 0))

i = 0
for name in detector_names:
    if name != 'face' and name != 'profile':
        cv.NamedWindow(name)
        cv.ResizeWindow(name, *(320, 200))
        cv.MoveWindow(name, *(0, 480 + (200 * i)))
        i = i + 1

capture = cv.CaptureFromCAM(0)
feature_detectors = []
for file in cascade_files:
Ejemplo n.º 30
0
    capture = scanCard.check_for_card()
    if capture is not None:
        print "Card captured, proceeding to find a match"
        (card,
         set_name), is_sure = match_card.match_card(capture, known, cache)

        # Display matched information
        if is_sure == True:
            print "\tMatch Found!"
            #card = unicode(card.decode('UTF-8'))

            path = os.path.join(BASE_SET_DIR, set_name, card + ".full.jpg")
            try:
                tmp = cv.LoadImage(path)
                overlay_text_on_image(tmp, "%s - %s" % (card, set_name), font)
                cv.ShowImage("match", tmp)
                cv.ResizeWindow("match", 800, 600)
                match_pending = True
            except IOError:
                print "test.py Could not load card %s" % (path)

        else:
            print "\tMatch not found"

    scanCard.display_snapshot()
    key_code = cv.WaitKey(10)
    if key_code == 114:
        scanCard.update_background()
        scanCard.display_background()
        print "Updated background image"