Proview and OpenCV
- Counting, observation, quality control...
- Standard USB webcam
- Lenovo R500 laptop
Starting, as simple as possible.., with colors only...:
- Detecting one color by using a Python script
- While continuous scanning in a loop, if the color based (pixel) object has been detected a "Val=1", is going to be written to a text file in RAM
- In Proview: based on a OneWire object
- In a Graph visualisation of the detected color
- OpenCV is using lots of CPU resources
- Solution: low webcam resolution, In first case I only want to track color changes and don't have a decent PC/Laptop anyway....
- The need of a stable light source
- I am going to use the balls of my dog (meaning his toys) but they are "shiny" and a kind of transparent
- "He" must be sleeping otherwise he is freaking out. Don't play with his balls
- Shiny and transparent....., lets give it a try..
"The balls" of my dog (can't find the yellow one):
First try: The blue ball
Hunted a script.
import numpy as np
cap = cv2.VideoCapture(0)
# Take each frame
_, frame = cap.read()
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of blue color in HSV
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_blue, upper_blue)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
k = cv2.waitKey(5) & 0xFF
if k == 27:
Useless.., completely out of the range.
In OpenCV it's common tu use the HSV color model not RGB. The HSV color space is quite similar to the way in which humans perceive color.
HSV (Hue-Saturation-Value) numbers:
- Hue : Color / Tint
- Saturation: Amount of gray
- Value: Brightness / Luminance
Hue is expressed as a number from 0 to 360 degrees representing hues of red (starts at 0), yellow (starts at 60), green (starts at 120), cyan (starts at 180), blue (starts at 240), and magenta (starts at 300).
Saturation is the amount of gray (0% to 100%) in the color.
Value "works" with saturation and describes the brightness or intensity of the color from 0% to 100%.
Let's have a look at the "color picker" of Gimp and the blue ball. I selected the color from "the middle" of the ball.
H = 201 (0-360)
S = 88 (0-100)
V = 45 (0-100)
It seems to be the blue ball is cyan (greenish blue) because the H=201. Doesn't matter...
I don' want to hassle with a color picker so in the next screen shot I am using a real time tool to find quickly the HSV combination for the colored object to track.
Can't find the blue ball so I am using the red one.
Next step is to find a decent radius range, of the circle (cvCircle), to prevent noise errors.
A Python script writes to a file in /dev/shm. If the ball is detected Val=1 and Val=0 if no object is detected.
Result in Proview:
Detection of the ball in a graph.
With Python you can detect multi colors as well ,so it's possible to use different colored objects.....
The next step is to use real object recognition and not an object based on it's color model.
I am going to use opentld, The young guy behind could have made a fortune if he sold his algorithm to Google, Facebook or others in 2011. But he decided to give it free to the world (GPL-license).
The great thing is OpenTLD has a learning mode.
- My old laptop, learning mode uses lots of CPU so I am not sure if I can make a Desktop recording. Search on Google if you want to know more.
Learning mode (10 fps)
- Comparing "objects" in combination with Proview......
Imagine a factory with a production line with the next produkt:
With Proview we can count in different ways and get, in a sequence, a sample to do a quality check with Python, OpenCV and a webcam.
Based on this tutorial OpenCV-doc
- Get the accepted fault tolerance
- Proview triggers a webcam and creates a picture shot
- A Python/OpenCV script is comparing the histograms (base and sample) and calculates the numerical matching parameters
- An alarm will become triggered in Proview if the fault tolerance crosses the limit
Problems and weakness:
- Stable light source required
- Background and placement must be exactly the same
- 2D snapshot
Click : Next