Proview and OpenCV

 

Goal:

 Ingredients:

Starting, as simple as possible.., with colors only...:

Problems:

 

"The balls" of my dog (can't find the yellow one):

 

First try: The blue ball

Hunted a script.

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while(1):

    # 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)

    cv2.imshow('frame',frame)
    cv2.imshow('mask',mask)
    cv2.imshow('res',res)
    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

cv2.destroyAllWindows()

Result:

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 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.

blue-ball.png

 

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.

Ranges: 0-255

 

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.

Problem:

OpenTld:

Learning mode (10 fps)

tld1.png

 

Next step:

Imagine a factory with a production line with the next produkt:

1.jpg

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

Steps:

Problems and weakness:


 

Click : Next

Edukits