Wednesday, 17 June 2015

Tracking Colour Changed, GPIO Output Control, Frame-Rate Play, Code Modified to Trigger LED - 18/06/15

Today was great for progress!  First point of call was to change the BGR values found in the code:

lower = np.array([76,31,4],dtype="uint8") upper = np.array([210,90,70], dtype="uint8")

This original value was set to blue and because we had an orange slot card, we decided to go for orange values. The lower and upper values provide a threshold spectrum for the colour range you want to work with. For example, from dark orange to light orange. This is the code adjusted for orange:


lower = np.array([10,100,200],dtype="uint8")
upper = np.array([50,150,250], dtype="uint8")

After that, we tested it and it worked as it started to track our orange slot card!  However, it was slightly laggy which cannot be applicable for our project as a quick responding warning system is needed. First the size of the video capture feed was reduced from 640x480 to 480x320. Afterwards, the frame-rate was increased to 90. The response was much more fluid and quicker which now suits our application.

After this, we started to import the GPIO (General Purpose Inputs and Outputs) library and to declare which pins are outputs:

import RPi.GPIO as GPIO # Imports GPIO library
GPIO.setmode(GPIO.BOARD) # Use board pin numbering GPIO.setup(36, GPIO.OUT) # Pin 36 set as out GPIO.setup(40, GPIO.OUT) # Pin 40 set as out

Then a simple LED circuit was connected to pin 36 (GPIO 16) to prove that the LED can be triggered via object tracking. It is worth noting that the output voltage of the Pi is 3.3V. The code lines used are:




The code changes worked! We are now able to smoothly track an orange card, and once detected, the LED will turn on and if out of site, the LED is off!


Lastly we noticed that the LED will stay on if we quit the application as it tracks the object.  We then added a few lines to break the loop once you press "q" to quit:

        # if the `q` key was pressed, break from the loop
        if key == ord("q"):
                GPIO.output(36,GPIO.LOW)
                GPIO.output(40,GPIO.LOW)
                break

Here is the demonstration of the LED actuation when object is detected:


The next step is to now design and build the warning system circuit with necessary chip protection lines and to fit and mount the Pi to an RC car and demonstrate it on an artificial road.






No comments:

Post a Comment