Ejemplo n.º 1
0
def run():
    global pixels
    global grid

    acabsl_rconfig.set_all(b_color)
    grid=None
    pixels=None
    do_detect()
    print pixels
    grid=gridify(pixels)
    print grid
    send_config(grid)
def run():
    global pixels
    global grid

    acabsl_rconfig.set_all(b_color)
    grid = None
    pixels = None
    do_detect()
    print pixels
    grid = gridify(pixels)
    print grid
    send_config(grid)
Ejemplo n.º 3
0
def main():
    global cap
    global pixels,grid
    global do_run
    
    # Init OpenCV
    if cam_index <0:
        cap=MockCamera()
    else:
        cap = cv2.VideoCapture(cam_index) # Video capture object
        cap.open(cam_index) # Enable the camera
        
        #cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH,320)
        #cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT,200)
        
        cap.set(cv2.cv.CV_CAP_PROP_EXPOSURE, 0)
        #cap.set(cv2.cv.CV_CAP_PROP_WHITE_BALANCE, 0) # not implemented yet
    
    # Init rconfig 
    acabsl_rconfig.set_target(UDP_IP,UDP_PORT)
    
    # Setup OpenCV GUI
    cv2.namedWindow('ctrl', cv2.WINDOW_NORMAL)
    cv2.namedWindow('frame', cv2.WINDOW_NORMAL)
    cv2.moveWindow('frame', 300, 0)
    cv2.setMouseCallback('frame',move_point)
    if diffmode ==0:
        cv2.resizeWindow('ctrl', 250, 300)
        cv2.createTrackbar('H-','ctrl', 90,255,nothing)
        cv2.createTrackbar('H+','ctrl',140,255,nothing)
        cv2.createTrackbar('S-','ctrl', 20,255,nothing)
        cv2.createTrackbar('S+','ctrl',255,255,nothing)
        cv2.createTrackbar('V-','ctrl',100,255,nothing)
        cv2.createTrackbar('V+','ctrl',255,255,nothing)
    else:
        cv2.createTrackbar('V-','ctrl',210,255,nothing)
        cv2.createTrackbar('V+','ctrl',255,255,nothing)
    cv2.createTrackbar('pixel_if','ctrl',def_pixel_if,len(interfaces)-1,pixel_if)
    cv2.createTrackbar('pixel_addr','ctrl',0,255,pixel)
    cv2.createTrackbar('run','ctrl',0,1,nothing)
    
    if pixels is not None:
        grid=gridify(pixels)
        send_config(grid)
    
    did_run=False
    
    acabsl_rconfig.set_all(b_color)
    pixel(cv2.getTrackbarPos('pixel','ctrl'))
    
    
    if diffmode == 0:
      print "The wall should now be green and the lamps on the selected interface blue"
      print "The blue area should be marked with an red line"
      print "(you can also try the other mode with cmd line option --diff)"
    else:
      print "The lamps on the selected interface should now be red, all other lamps black."
    print ""
    print "Change pixel_if and pixel_addr slider to see if everything works"
    print ""   
    print "If you need to select different interfaces use cmd line option -i 1,2,3,4,5,6"
    print "For additional options see source code header or https://wiki.muc.ccc.de/acab:setup#auto_configuration_via_webcam "
    print ""
    print "When you are ready, move run slider to the right."  
    print ""
    print "You can also quit this program by focusing on the other window and hitting ESC. "
    print ""

    while True:
        if cv2.getTrackbarPos('run','ctrl')==1 and not did_run:
            do_run=True
        elif cv2.getTrackbarPos('run','ctrl')==0:
            did_run=0

        if do_run:
            run()
            did_run=True
            do_run=False

        find_pixel(True)
        k = cv2.waitKey(20) & 0xFF
        if k == 27: # Escape key
            cv2.destroyAllWindows()
            cap.release()
            break
def main():
    global cap
    global pixels, grid
    global do_run

    # Init OpenCV
    if cam_index < 0:
        cap = MockCamera()
    else:
        cap = cv2.VideoCapture(cam_index)  # Video capture object
        cap.open(cam_index)  # Enable the camera

        #cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH,320)
        #cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT,200)

        cap.set(cv2.CAP_PROP_EXPOSURE, 0)


#        cap.set(cv2.CAP_PROP_WHITE_BALANCE, 0) # not implemented yet

# Init rconfig
    acabsl_rconfig.set_target(UDP_IP, UDP_PORT)

    # Setup OpenCV GUI
    cv2.namedWindow('ctrl', cv2.WINDOW_NORMAL)
    cv2.namedWindow('frame', cv2.WINDOW_NORMAL)
    cv2.moveWindow('frame', 300, 0)
    cv2.setMouseCallback('frame', move_point)
    if diffmode == 0:
        cv2.resizeWindow('ctrl', 250, 300)
        cv2.createTrackbar('H-', 'ctrl', 90, 255, nothing)
        cv2.createTrackbar('H+', 'ctrl', 140, 255, nothing)
        cv2.createTrackbar('S-', 'ctrl', 20, 255, nothing)
        cv2.createTrackbar('S+', 'ctrl', 255, 255, nothing)
        cv2.createTrackbar('V-', 'ctrl', 100, 255, nothing)
        cv2.createTrackbar('V+', 'ctrl', 255, 255, nothing)
    else:
        cv2.createTrackbar('V-', 'ctrl', 210, 255, nothing)
        cv2.createTrackbar('V+', 'ctrl', 255, 255, nothing)
    cv2.createTrackbar('pixel_if', 'ctrl', def_pixel_if,
                       len(interfaces) - 1, pixel_if)
    cv2.createTrackbar('pixel_addr', 'ctrl', 0, 255, pixel)
    cv2.createTrackbar('run', 'ctrl', 0, 1, nothing)

    if pixels is not None:
        grid = gridify(pixels)
        send_config(grid)

    did_run = False

    acabsl_rconfig.set_all(b_color)
    pixel(cv2.getTrackbarPos('pixel', 'ctrl'))

    if diffmode == 0:
        print "The wall should now be green and the lamps on the selected interface blue"
        print "The blue area should be marked with an red line"
        print "(you can also try the other mode with cmd line option --diff)"
    else:
        print "The lamps on the selected interface should now be red, all other lamps black."
    print ""
    print "Change pixel_if and pixel_addr slider to see if everything works"
    print ""
    print "If you need to select different interfaces use cmd line option -i 1,2,3,4,5,6"
    print "For additional options see source code header or https://wiki.muc.ccc.de/acab:setup#auto_configuration_via_webcam "
    print ""
    print "When you are ready, move run slider to the right."
    print ""
    print "You can also quit this program by focusing on the other window and hitting ESC. "
    print ""

    while True:
        if cv2.getTrackbarPos('run', 'ctrl') == 1 and not did_run:
            do_run = True
        elif cv2.getTrackbarPos('run', 'ctrl') == 0:
            did_run = 0

        if do_run:
            run()
            did_run = True
            do_run = False

        find_pixel(True)
        k = cv2.waitKey(20) & 0xFF
        if k == 27:  # Escape key
            cv2.destroyAllWindows()
            cap.release()
            break