Αναζήτηση

Powered By Blogger

Jan 13, 2016

Color Identifier with Python and OpenCV

Color Identifier with Python and OpenCV:



OpenCV Logo
A while back a friend of mine asked me to help him build an app that used computer vision to detect things like traffic lights & road signs. The idea was to use his Raspberry Pi and Pi Cam as a dashcam in his car. He wanted it to identify traffic lights that were red and play some sort of sound letting him know the light was red and that he needed to stop. Once the light turned green, it would play another sound letting him know that he could proceed. He also wanted to have the app do several other things, all of which were based off of color. Normally I would recommend using something such as a Haar classifier or dedicated algorithm for detecting such objects. But, I also wanted to see for myself whether it would be possible to detect objects based entirely on their color. The results were actually very good and the speed of the app outperformed some of the best algorithms available.

In order for me to know the RGB values of the objects he wanted to detect, I wrote a simple tool that uses Python and OpenCV to filter out all colors except the colors I am interested in, leaving me with the RGB values I needed to plug into the app. Now, I know that there are plenty of tools out there that can be used to identify RGB values of objects in images. But, being the geek that I am, I opted to write my own tool. Plus, this was just another opportunity for me to do some work with computer vision. Since I enjoyed playing around with this tool and found it helpful for my friend’s dashcam project, I thought I would share the app in case anyone else might also find it useful / fun.

Aside from Python, the only thing you need is the OpenCV library compiled for Python. If you don’t have it, don’t worry. I’ve included it in the ZIP linked to at the end of this post. You will also need some images to play with. Since one of the objects my friend wanted to detect was a red traffic light, I have also included 3 images in the ZIP that contain scenes from intersections. Here is the image I used as a demo when writing this post.



traffic_light2


You can swap out my images with whatever images you want by simply replacing the image_filename at the beginning of the code with the path to your image of choice. Once you’ve done that, run the Python app. The app will launch a window that contains slider bars at the top and your image at the bottom. Simply adjust the sliders at the top of the app and you will see colors get filtered from your image. Here are a couple of screenshots of my demo while adjusting the sliders.



outlines_half




outlines


If you keep adjusting the sliders, you will eventually end up with the RGB values for only the color you are looking for as shown in this final result from filtering out everything except the red traffic lights.



red_lights_only


As you can see in the source code below, I have already hardcoded the best values for each of the test images included in the ZIP. When you run the app, the sliders will default to these values (assuming you have uncommented the values for the image you are using). Feel free to modify these values (or the rest of the code) to fit your needs. Enjoy!

import cv2.cv as cv

image_filename = 'images/traffic_light2.jpg'

#traffic_light1.jpg
#mR_val = 254
#mG_val = 105
#mB_val = 0
#MAR_val = 256
#MAG_val = 138
#MAB_val = 17

#traffic_light2.jpg
mR_val = 172
mG_val = 136
mB_val = 150
MAR_val = 256
MAG_val = 256
MAB_val = 256

#traffic_light3.jpg
#mR_val = 144
#mG_val = 100
#mB_val = 134
#MAR_val = 256
#MAG_val = 256
#MAB_val = 205

def set_RGB(pos):
    mR_val = cv.GetTrackbarPos('minR', winName)
    mG_val = cv.GetTrackbarPos('minG', winName)
    mB_val = cv.GetTrackbarPos('minB', winName)

    MAR_val = cv.GetTrackbarPos('maxR', winName)
    MAG_val = cv.GetTrackbarPos('maxG', winName)
    MAB_val = cv.GetTrackbarPos('maxB', winName)
    
    min_color = cv.CV_RGB(mR_val, mG_val, mB_val)
    max_color = cv.CV_RGB(MAR_val, MAG_val, MAB_val)
    cv.InRangeS(hsv, min_color, max_color, mask)
    cv.ShowImage(winName, mask)

# setup window
winName = 'Color Identifier'
cv.NamedWindow(winName, cv.CV_WINDOW_AUTOSIZE)

min_color = cv.CV_RGB(mR_val, mG_val, mB_val)
max_color = cv.CV_RGB(MAR_val, MAG_val, MAB_val)

cv.CreateTrackbar('minR', winName, mR_val, 256, set_RGB)
cv.CreateTrackbar('minG', winName, mG_val, 256, set_RGB)
cv.CreateTrackbar('minB', winName, mB_val, 256, set_RGB)

cv.CreateTrackbar('maxR', winName, MAR_val, 256, set_RGB)
cv.CreateTrackbar('maxG', winName, MAG_val, 256, set_RGB)
cv.CreateTrackbar('maxB', winName, MAB_val, 256, set_RGB)

img = cv.LoadImage(image_filename)
hsv = cv.CreateImage(cv.GetSize(img), 8, 3)
cv.CvtColor(img, hsv, cv.CV_BGR2HSV)
mask = cv.CreateImage(cv.GetSize(img), 8, 1)
cv.Zero(mask)

cv.InRangeS(hsv, min_color, max_color, mask)

# show image
cv.ShowImage(winName, mask)
cv.WaitKey(0)
cv.DestroyWindow(winName)
Download: Python source code, OpenCV library, and test images. (5.5MB ZIP)

The post Color Identifier with Python and OpenCV appeared first on Prodigy Productions, LLC.

Arduino ProtoShield

Arduino ProtoShield:

FU4B4KFIJAAAIX7.SMALL.jpg
In this project, we will be making an Arduino Protoshield which supports and electrically connects electronics components to the Arduino for better wiring and design.It’s a fairly easy project and could be used on variety projects. List of Material For this project, we will be using:- Arduino boa...

By: AdrieSentosa



Continue Reading »


Low Cost Foundry/forge

Low Cost Foundry/forge:

FGK1LLEII7PH5VD.SMALL.jpg
This is my design for a metal melting foundry that also works as a forge. Materials needed: 1 old beat up standard propane tank Portland cement Silica sand Wood ashPerlite (not vermiculite) Fireclay External parts:Forge burner------ I used the burner from this instructablehttp://www.instructables.co...

By: chaotech creations



Continue Reading »


Zip Tie Stand-offs

Zip Tie Stand-offs:

FM2VGFHIJBTVZU6.SMALL.jpg
What I want to share with you is a little trick I discovered for tidying up wires, brake lines, cables ect. along frame rails, cross members, or anywhere you would be running such stuff. I've used this technique on motorcycles for running hard brake lines along side frame sections with great results...

By: mech4fun



Continue Reading »


Jan 12, 2016

Guide to ESP8266 and Tweeting Using ESP8266

Guide to ESP8266 and Tweeting Using ESP8266:



FONIOTZIJ5TYSJH.MEDIUM


Subhan95 @ instructables.com has written a tutorial on how to use ESP8266 with Arduino and tweet using it.

What can the ESP8266 do?It is limited by your imagination.I have seen projects and tutorials on the internet showing how to fetch a city’s temperature, stock prices,sending and receiving emails ,making phone calls and much much more.I will show in this Instructable how to send a tweet.
Guide to ESP8266 and Tweeting Using ESP8266 – [Link]

The post Guide to ESP8266 and Tweeting Using ESP8266 appeared first on Electronics-Lab.

Jan 11, 2016

SerialUSB: A cheap USB proxy for input devices

SerialUSB: A cheap USB proxy for input devices:



687474703a2f2f67696d782e66722f696d672f73657269616c7573622f73657269616c7573622d6370323130322d776972696e672d732e706e67


Serialusb is a cheap (~$5) USB proxy intended to be used with input devices. It is the combination of:

  • a PC software operating the host side of the proxy
  • an atmega32u4 firmware operating the device side of the proxy
SerialUSB: A cheap USB proxy for input devices – [Link]

The post SerialUSB: A cheap USB proxy for input devices appeared first on Electronics-Lab.

chipKIT Tutorial: Using Nokia 5110 LCD

chipKIT Tutorial: Using Nokia 5110 LCD:



T7_Title-580x447


Raj @ embedded-lab.com has posted another great tutorial on how to interface a Nokia 5110 LCD to chipKIT board.

Today, we will see how to connect a NOKIA 5110 graphical LCD (used in Nokia 5110 cell phones), which is a 84×48 pixel monochrome display of about 1.5″ diagonal in size. The display can be used for graphics, text, and bitmaps.
chipKIT Tutorial: Using Nokia 5110 LCD – [Link]

The post chipKIT Tutorial: Using Nokia 5110 LCD appeared first on Electronics-Lab.

Jan 9, 2016

5V from Portable Wind Turbine

5V from Portable Wind Turbine 

5V from Portable Wind Turbine 

T.K. Hareendran

This project deals with the design and development of a portable wind turbine unit, capable of generating electricity from the kinetic energy in the wind. The circuit requires a DC motor, fan blades or propeller, DC-DC boost converter and wind energy to produce a 5V DC output.

Wind-power generation is a fairly simple process that uses an ordinary miniature DC motor to make a very simple wind turbine generator. A miniature DC motor, like RF-300FA-12350, is easily available in the market but can also be taken out from an old CD/DVD drive/player (refer Fig. 1).

Fig. 1: Miniature DC motor

Fig. 2: Wind turbine blades/propeller 

Fig. 3: DC-DC boost converter
  
  Fig. 4: Circuit diagram for deriving 5V from the
  portable wind turbine
A small propeller, or fan blades, can be mounted directly onto the motor shaft. Note that the electricity generated by the motor is DC, and hence no AC-DC conversion circuitry is required apart from a polarity guard diode. In fact, the polarity guard diode is also not required since the propeller rotates in only one direction (counter-clockwise) in this model, due to the unique design structure of the plastic wind turbine blades/propeller.

Compact and light-weight plastic fan blades/propellers are available. A generic three-leg plastic propeller (shown in Fig. 2) is used in this project.

Jan 1, 2016

INA219 current sensor DIY Breakout board

INA219 current sensor DIY Breakout board:



23577455661_4c48a0beca_z


INA219 current sensor DIY Breakout board project from Juan Ignacio:

Another small board, this time for a INA219. The INA219 is a high-side current shunt and power monitor with an I2C interface.

For testing I used Rei VILO library with a MSP430G2553 and Energia, and I measured the power consumption for this simple circuit.
Project info at ssihla homepage.

Reverse engineering the ESP8266 WIFI-to-Serial port adapter

Reverse engineering the ESP8266 WIFI-to-Serial port adapter:



Here’s a video from electronupdate on reverse engineering the ESP8266 WIFI-to-Serial port adapter:

Another very interesting bit of technology. The combination of so much functionality into such a small part is a real touch-stone as to where things are heading.

A quick look at the antenna design to see if I could sort down the details and then some die-decap to analyze the silicon a bit. The RF section is especially interesting. In the video I call out a section as being an inductor… on second thought as I type this it might even be a transformer?

Amazing…
More details at electronupdate blog.

Dec 30, 2015

ESP8266 WiFI LED controller hack

ESP8266 WiFI LED controller hack:



P1020335


Andreas Hölldorfer of ChaozLabs wrote an article detailing how he hacked the cheap WiFi LED controller:

This pictures show the PCB. As you can see there are pins labeled as RX,TX,GND,3.3V. I simply connected an USB-Serial converter to the pins. The two other pins are GND and GPIO0. If you set a jumper between this two pins, the controller starts in bootloader mode.

The chip above is a NXP HC245, a 3-state Octal bus transceiver. It is used to drive the N-channel MOSFETS (20N06L – 20 A, 60 V, N−Channel DPAK).

The power supply is a 2 stage design. A AOZ1212 3A Simple Buck Regulator to convert the input voltage to about 5V and an AMS1117 low dropout voltage regulator to get 3.3V.
More info at ChaozLabs site.

Check out the video after the break.



Ultimate classic game console joystick to USB adapter

Ultimate classic game console joystick to USB adapter:



FinalVersion


Matthew Heironimus posted a step by step guide of his “ultimate” classic game console joystick to USB adapter build:

This article describes how to use an Arduino Leonardo or Arduino Micro to make up to three classic console joysticks (e.g. Atari 2600, ColecoVision, and possibly others) available to a modern computer (e.g. Windows PC, Mac, or Linux). This adapter can be placed into one of the following modes:

* Joystick Mode

Each of the three classic console joysticks appear as a Game Controller.
* ADAMEm Mode

Configured for use with the ADAMEm emulator. Joystick 1’s direction and fire buttons are mapped to a Game Controller and the keypad is mapped to the keyboard’s numeric keypad keys. Joystick 2 is mapped to keyboard keys (e.g. up arrow key, down arrow key, etc.). This allows ADAMEm to support two player games. Joystick 3 is not used in this mode.
* MAME Mode

Configured for use with the MAME emulator. All three joysticks’ direction and fire buttons are mapped to the three Game Controllers. The numeric keys on all three joysticks are mapped to keyboard keys.
Project info at Heironimus’ blog.

Dec 28, 2015

Auto Power Off: save batteries

Auto Power Off: save batteries:

FP6CE04IIOWQM48.SMALL.jpg
This little circuit allows your microcontroller to cut the power off. To turn the circuit on press the button.To turn it off drive the "to microcontroller" signal high using whichever condition you like. For battery applications you might want to have a voltage reading on another pin (a voltage divi...

By: gab3iel



Continue Reading »


Dec 27, 2015

9 Different Desoldering Techniques - All

9 Different Desoldering Techniques - All: 9 Different Desoldering Techniques by Proto G

Picture of 9 Different Desoldering Techniques

ARDUINO photogate for HIGH SPEED photography

ARDUINO photogate for HIGH SPEED photography:

FV0YA7MIHKWFGBG.SMALL.jpg
Over the last few weeks I have been searching the internet for high speed photograph using a ARDUINO, So far over 90% of the projects I found used sound as the trigger. If you are trying to get a picture of a balloon popping that would work fine. But what I was after was pictures of water splashes a...

By: Z-HUT



Continue Reading »