コード例 #1
0
ファイル: psvd_setup.py プロジェクト: tommybehner/PSVD
    def turnOnCamera(self):
        """
        Instruct the user how to take a new setup image, then activate 
        the PiCam. If the camera fails to load, catch the exception and present
        error message.

        """
        # show quick dialogue box with basic instruction
        tkMessageBox.showinfo(
            title="",
            message="Press the ENTER key to take a new setup image " +
            "or the ESCAPE key to cancel.")

        try:
            # initialise the camera using the settings in the imageread module
            self.__camera = imageread.setup_camera(is_fullscreen=True)
            self.__camera.awb_mode = 'auto'
            self.__camera.exposure_mode = 'auto'
            self.__camera.start_preview()
            self.__camera_is_active = True
            if self.__is_verbose: print "INFO: PiCam activated."
        except:
            # camera failed to load, display error message
            tkMessageBox.showerror(
                title="Error!",
                message="Error: Failed to setup and start PiCam.")
コード例 #2
0
def main():

    global has_quit
    global camera

    camera = imageread.setup_camera(is_fullscreen = False)

    try:
        thread.start_new_thread(create_application, ())
        thread.start_new_thread(run, ())
    except:
    	print "ERROR: Failed new thread"

    while not has_quit:
    	pass
コード例 #3
0
ファイル: pipark_setup.py プロジェクト: kaser4728/emso
    def turnOnCamera(self):

        tkMessageBox.showinfo(
            title="",
            message="Press the ENTER key to take a new setup image " +
            "or the ESCAPE key to cancel.")

        try:

            self.__camera = imageread.setup_camera(is_fullscreen=True)
            self.__camera.awb_mode = 'auto'
            self.__camera.exposure_mode = 'auto'
            self.__camera.start_preview()
            self.__camera_is_active = True

        except:
            tkMessageBox.showerror(
                title="Error!",
                message="Error: Failed to setup and start PiCam.")
コード例 #4
0
ファイル: main.py プロジェクト: tommybehner/PSVD
def main():
    """Start PSVD application loop. """

    # use global variables
    global has_quit
    global camera

    # instantiate the camera object to global camera variable
    camera = imageread.setup_camera(is_fullscreen=False)

    # now create two threads, one in which to run the MainApplication and
    # the other the run the main program loop.

    try:
        thread.start_new_thread(create_application, ())
        thread.start_new_thread(run, ())
    except:
        print "ERROR: Failed to start new thread."

    # do not end main thread until user has quit and destroyed the application
    while not has_quit:
        pass
コード例 #5
0
ファイル: main.py プロジェクト: Humpheh/PiPark
def main():
    """Start PiPark application and Smart Parking System loop. """
    
    # use global variables (Oh D-d-d-dear)!
    global has_quit
    global camera
    
    # instantiate the camera object to global camera variable
    camera = imageread.setup_camera(is_fullscreen = False)
    
    # now create two threads, one in which to run the MainApplication and
    # the other the run the main program loop.
    
    try:
        thread.start_new_thread(create_application, ())
        thread.start_new_thread(run, ())
    except:
    	print "ERROR: Failed to start new thread. =("
        
    # do not end main thread until user has quit and destroyed the application
    while not has_quit:
    	pass
コード例 #6
0
ファイル: pipark_setup.py プロジェクト: cgonfe/PiPark
    def turnOnCamera(self):
        """
        Instruct the user how to take a new setup image, then activate 
        the PiCam. If the camera fails to load, catch the exception and present
        error message.

        """
        # show quick dialogue box with basic instruction
        tkMessageBox.showinfo(title = "",
            message = "Press the ENTER key to take a new setup image "
            + "or the ESCAPE key to cancel.")

        
        try:
            # initialise the camera using the settings in the imageread module
            self.__camera = imageread.setup_camera(is_fullscreen = True)
            self.__camera.start_preview()
            self.__camera_is_active = True
            if self.__is_verbose: print "INFO: PiCam activated."
        except:
            # camera failed to load, display error message
            tkMessageBox.showerror(title = "Error!",
                message = "Error: Failed to setup and start PiCam.")
コード例 #7
0
    def turnOnCamera(self):
        """
        Instruct the user how to take a new setup image, then activate 
        the PiCam. If the camera fails to load, catch the exception and present
        error message.

        """
        # show quick dialogue box with basic instruction
        tkMessageBox.showinfo(
            title="",
            message="Press the ENTER key to take a new setup image " +
            "or the ESCAPE key to cancel.")

        try:
            # initialise the camera using the settings in the imageread module
            self.__camera = imageread.setup_camera(is_fullscreen=True)

            #preview window
            while True:
                ret, frame = self.__camera.read()
                rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
                cv2.imshow('frame', rgb)
                if cv2.waitKey(1) & 0xFF == ord('\x0D'):
                    cv2.destroyWindow('frame')
                    break

            #self.__camera.awb_mode = 'auto';
            #self.__camera.exposure_mode = 'auto';
            #self.__camera.start_preview()
            #self.__camera_is_active = True
            #if self.__is_verbose: print "INFO: PiCam activated."

        except:
            # camera failed to load, display error message
            tkMessageBox.showerror(
                title="Error!",
                message="Error: Failed to setup and start PiCam.")
コード例 #8
0
def main():
    """
    Run main program loop. Detect changes to parking spaces and update 
    appropriate availabity of the spaces to the server.
    
    """

    # setup camera and image save location
    camera = imageread.setup_camera()
    camera.start_preview()
    image_location = "./images/pipark.jpeg"

    # load data sets and count num spaces on control boxes
    space_boxes, control_boxes = __setup_box_data()

    num_spaces = len(space_boxes)
    num_controls = len(control_boxes)

    print "Number of spaces:", num_spaces, "Number of Control boxes:", num_controls

    assert num_spaces > 0
    assert num_controls == 3

    last_status = [None for i in range(10)]
    last_ticks = [3 for i in range(10)]

    # run centralised program loop
    while True:
        space_averages = []
        control_averages = []

        # take new picture, save to specified location
        camera.capture(image_location)
        print "INFO: New picture taken,", image_location

        # load image
        try:
            image = imageread.Image.open(image_location)
            pixels = image.load()
        except:
            print "ERROR: Image has failed to load."

        # setup spaces
        for space in space_boxes:
            space_x = space[2]
            space_y = space[3]
            space_w = abs(space[4] - space[2])
            space_h = abs(space[5] - space[3])

            #space_x, space_y, space_w, space_h = __get_area_values(space)

            print "Space dims:", "x", space_x, "y", space_y, "w", space_w, "h", space_h

            space_averages.append(
                imageread.get_area_average(pixels, space_x, space_y, space_w,
                                           space_h))

        # setup control
        for control in control_boxes:

            control_x = control[2]
            control_y = control[3]
            control_w = abs(control[4] - control[2])
            control_h = abs(control[5] - control[3])

            #control_x, control_y, control_w, control_h = __get_area_values(control)

            print "Control dims:", "x", control_x, "y", control_y, "w", control_w, "h", control_h

            control_averages.append(
                imageread.get_area_average(pixels, control_x, control_y,
                                           control_w, control_h))

        print "\n\n"
        # compare control points to spaces
        for i, space in zip(space_boxes, space_averages):

            num_controls = 0
            for control in control_averages:
                if imageread.compare_area(space, control):
                    num_controls += 1

            # Determine if occupied
            is_occupied = False
            if num_controls >= 2: is_occupied = True

            print "INFO: Space", i[0], "is", ("occupied" if is_occupied else
                                              "vacant"), "\n"

            if last_status[i[0]] != is_occupied:
                print "INFO: Detected change in space", i[0]
                print "INFO: Space", i[0], "has been the", (
                    "occupied" if is_occupied else
                    "vacant"), "for", last_ticks[i[0]], "tick(s).\n"
                if last_ticks[i[0]] < 3:
                    last_ticks[i[0]] += 1
                else:
                    last_status[i[0]] = is_occupied
                    last_ticks[i[0]] = 1
                    print "INFO: Space", i[
                        0], "has changed status, sending update to server...\n"
                    num = 1 if is_occupied else 0
                    print senddata.send_update(i[0], num), "\n"
            else:
                last_ticks[i[0]] = 1

            # old version
            """if num_controls >= 2:
               # last_status
                print "INFO: Space", i[0], "occupied!"
                print senddata.send_update(i[0], 1), "\n"
            else:
                print "INFO: Space", i[0], "vacant!"
                print senddata.send_update(i[0], 0), "\n" """

        print "INFO: Sleeping for 5s"
        imageread.time.sleep(5)
コード例 #9
0
ファイル: setup.py プロジェクト: wlstks7/PiPark
def __main():
    """Main function for setup.py. Contains and handles the menu loop."""
    
    print """
--------------------------------------------------------------------------------
    
                             Setup for PiPark, 2014
    
================================================================================
    """
    
    # continually loop menu unitl user chooses 'q' to quit
    setup_image_location = "./images/setup.jpeg"
    while True:
        user_choice = __menu_choice()
        
        if user_choice == '1':
            # initialise camera and start pi camera preview
            camera = imageread.setup_camera()
            camera.start_preview()
            
            print "INFO: Setup image save location:", str(setup_image_location)
            print "INFO: Camera preview initiated."
            print ""
            
            # when user presses enter, take a new setup image. Then ask the user to confirm or
            # reject the image. If image is rejected, take a new image.
            while True:
                raw_input("When ready, press ENTER to capture setup image.")
                camera.capture(setup_image_location)
                user_input = raw_input("Accept image (y/n)? > ")
                
                if user_input.lower() in ('y', "yes"): break
                    
            # picture saved, end preview
            camera.close()
            print ""
            print "INFO: Setup image has been saved to:", str(setup_image_location)
            print "INFO: Camera preview closed."
        
        
        elif user_choice == '2':
            # check setup image exists, if not print error directing to option 1
            try:
                setup_image = Image.open(setup_image_location)
            except:
                print "ERROR: Setup image does not exist. Select option 1 to"
                print "create a new setup image."
            
            # setup image exists, so open GUI window allowing selection of spaces and
            # reference areas
            print """
When the window opens use the mouse to mark parking spaces and 3 reference
areas. Press T to toggle between marking parking spaces and reference areas and
the numbers 1 - 0 to mark new areas.
            """
            raw_input("\nPress ENTER to continue...\n")
            setup_selectarea.main(setup_image)
        
        
        elif user_choice == '3':
            # attempt to import the setup data and ensure 'boxes' is a list. If fail,
            # return to main menu prompt.
            try:
                import setup_data
                boxes = setup_data.boxes
                if not isinstance(boxes, list): raise ValueError()
            except:
                print "ERROR: Setup data does not exist. Please run options 1 and 2 first."
                continue
                
            # attempt to import the server senddata module. If fail, return to main menu
            # prompt.
            try:
                import senddata
            except:
                print "ERROR: Could not import send data file."
                continue
            
            # deregister all areas associated with this pi (start fresh)
            out = senddata.deregister_pi()
            
            try:
                out['error']
                print "ERROR: Error in connecting to server. Please update settings.py."
                continue
            except:
                pass
            
            # register each box on the server
            for box in boxes:
                if box[1] == 0:
                    senddata.register_area(box[0])
                    print "INFO: Registering area", box[0], "on server database."
                    
            print "\nRegistration complete."
        
        
        elif user_choice == '4':
            print "This will complete the setup and run the main PiPark program."
            user_input = raw_input("Continue and run the main program? (y/n) >")
            if user_input.lower in ('y', 'yes'):
                main.run_main()
                break
                                                 
        elif user_choice.lower() in ('h', "help"):
            print """
Welcome to PiPark setup, here's a quick run-through of the steps to successfully
setup your PiPark unit.
            
  1) Ensure that the PiPark unit is mounted suitable above the cark park so that
     the PiPark's camera is able to look down with a clear view upon the spaces
     that are required to be monitored.
            
  2) At the main menu prompt of this setup program enter option '1' to fine tune
     the direction of the camera so that it is clearly able to view the spaces.
     When you have finalised the position of the camera press ENTER to capture a
     setup image. If everything is correct and you do not wish to recapture the
     setup image, type 'y' or 'yes' at the prompt to continue the setup program.
     If you wish to recapture the setup image, type 'n' or 'no' at the prompt.
     
     Note: The setup image does not require the car park to be empty.

  3) Once back at the main menu prompt, enter option '2' to open up the setup
     GUI, which will open a new window allowing you to mark parking space areas
     and reference areas on the setup image that was captures as part of step 2.
     
     When the window has opened use the mouse to mark start and end corners of
     rectangles, which will represent the areas to be processed by the main
     program. To toggle between marking reference areas and parking space areas
     press 'T'. Blue areas represent parking spaces, and red areas represent
     reference areas.
     
     Currently up to ten areas can be marked, using the number keys from 1 - 0.
     There must be exactly 3 reference areas (RED) marked on the setup image
     and at least 1 parking space.
     
     When all areas have been marked on the image press 'O' to output the marked
     areas' co-ordinates to a file and close the window to continue completing
     the setup.
     
     Controls Summary:
       T -- Toggle between reference areas (RED) and parking spaces (BLUE).
       C -- Clear all marked areas.
       O -- Output the reference areas to a file.
       1 to 0 -- Change area ID numbers.

  4) The final step to completing the setup is to choose option '3' from the 
     main menu prompt. When selected the parking spaces will be registered to
     the server, and can now be viewed on the website.

  5) The setup is now complete; at the main menu prompt type 'q' or 'quit' to
     terminate the setup program. Alternatively, choose option 3 to immediately
     run the main PiPark program.
            """
            
            
        elif user_choice.lower() in ('q', "quit"):
            print ""
            break
        
        
        else:
            print "\nERROR: Invalid menu choice.\n"
コード例 #10
0
ファイル: main.py プロジェクト: mrwarni/PiPark
def main():
    """
    Run main program loop. Detect changes to parking spaces and update 
    appropriate availabity of the spaces to the server.
    
    """

    # setup camera and image save location
    camera = imageread.setup_camera()
    camera.start_preview()
    image_location = "./images/pipark.jpeg"

    # load data sets and count num spaces on control boxes
    space_boxes, control_boxes = __setup_box_data()

    num_spaces = len(space_boxes)
    num_controls = len(control_boxes)

    print "Number of spaces:", num_spaces, "Number of Control boxes:", num_controls

    assert num_spaces > 0
    assert num_controls == 3

    last_status = [None for i in range(10)]
    last_ticks = [3 for i in range(10)]

    # run centralised program loop
    while True:
        space_averages = []
        control_averages = []

        # take new picture, save to specified location
        camera.capture(image_location)
        print "INFO: New picture taken,", image_location

        # load image
        try:
            image = imageread.Image.open(image_location)
            pixels = image.load()
        except:
            print "ERROR: Image has failed to load."

        # setup spaces
        for space in space_boxes:
            space_x = space[2]
            space_y = space[3]
            space_w = abs(space[4] - space[2])
            space_h = abs(space[5] - space[3])

            # space_x, space_y, space_w, space_h = __get_area_values(space)

            print "Space dims:", "x", space_x, "y", space_y, "w", space_w, "h", space_h

            space_averages.append(imageread.get_area_average(pixels, space_x, space_y, space_w, space_h))

        # setup control
        for control in control_boxes:

            control_x = control[2]
            control_y = control[3]
            control_w = abs(control[4] - control[2])
            control_h = abs(control[5] - control[3])

            # control_x, control_y, control_w, control_h = __get_area_values(control)

            print "Control dims:", "x", control_x, "y", control_y, "w", control_w, "h", control_h

            control_averages.append(imageread.get_area_average(pixels, control_x, control_y, control_w, control_h))

        print "\n\n"
        # compare control points to spaces
        for i, space in zip(space_boxes, space_averages):

            num_controls = 0
            for control in control_averages:
                if imageread.compare_area(space, control):
                    num_controls += 1

            # Determine if occupied
            is_occupied = False
            if num_controls >= 2:
                is_occupied = True

            print "INFO: Space", i[0], "is", ("occupied" if is_occupied else "vacant"), "\n"

            if last_status[i[0]] != is_occupied:
                print "INFO: Detected change in space", i[0]
                print "INFO: Space", i[0], "has been the", ("occupied" if is_occupied else "vacant"), "for", last_ticks[
                    i[0]
                ], "tick(s).\n"
                if last_ticks[i[0]] < 3:
                    last_ticks[i[0]] += 1
                else:
                    last_status[i[0]] = is_occupied
                    last_ticks[i[0]] = 1
                    print "INFO: Space", i[0], "has changed status, sending update to server...\n"
                    num = 1 if is_occupied else 0
                    print senddata.send_update(i[0], num), "\n"
            else:
                last_ticks[i[0]] = 1

            # old version
            """if num_controls >= 2:
               # last_status
                print "INFO: Space", i[0], "occupied!"
                print senddata.send_update(i[0], 1), "\n"
            else:
                print "INFO: Space", i[0], "vacant!"
                print senddata.send_update(i[0], 0), "\n" """

        print "INFO: Sleeping for 5s"
        imageread.time.sleep(5)
コード例 #11
0
def __main():
    
    
    setup_image_location = "./images/setup.jpeg"
    while True:
        user_choice = __menu_choice()
        
        if user_choice == '1':
            
            camera = imageread.setup_camera()
            camera.start_preview()
            
            print "INFO: Setup image save location:", str(setup_image_location)
            print "INFO: Camera preview initiated."
            print ""
            
            
            while True:
                raw_input("When ready, press ENTER to capture setup image.")
                camera.capture(setup_image_location)
                user_input = raw_input("Accept image (y/n)? > ")
                
                if user_input.lower() in ('y', "yes"): break
                    
            # picture saved, end preview
            camera.close()
            print ""
            print "INFO: Setup image has been saved to:", str(setup_image_location)
            print "INFO: Camera preview closed."
        
        
        elif user_choice == '2':
            
            try:
                setup_image = Image.open(setup_image_location)
            except:
                print "ERROR: Setup image does not exist. Select option 1 to"
                print "create a new setup image."
            
        
            
            raw_input("\nPress ENTER to continue...\n")
            setup_selectarea.main(setup_image)
        
        
        elif user_choice == '3':
           
            try:
                import setup_data
                boxes = setup_data.boxes
                if not isinstance(boxes, list): raise ValueError()
            except:
                print "ERROR: Setup data does not exist. Please run options 1 and 2 first."
                continue
                
            # attempt to import the server senddata module. If fail, return to main menu
            # prompt.
            try:
                import senddata
            except:
                print "ERROR: Could not import send data file."
                continue
            
            # deregister all areas associated with this pi (start fresh)
            out = senddata.deregister_pi()
            
            try:
                out['error']
                print "ERROR: Error in connecting to server. Please update settings.py."
                continue
            except:
                pass
            
            # register each box on the server
            for box in boxes:
                if box[1] == 0:
                    senddata.register_area(box[0])
                    print "INFO: Registering area", box[0], "on server database."
                    
            print "\nRegistration complete."
        
        
        elif user_choice == '4':
            print "This will complete the setup and run the main PiPark program."
            user_input = raw_input("Continue and run the main program? (y/n) >")
            if user_input.lower in ('y', 'yes'):
                main.run_main()
                break
                                                 
        elif user_choice.lower() in ('h', "help"):
        
            
            
        elif user_choice.lower() in ('q', "quit"):
            print ""
            break
        
        
        else:
            print "\nERROR: Invalid menu choice.\n"