distance Meter

General discussion about topics related to OpenMV.
DavidMactavish
Posts: 14
Joined: Tue Sep 26, 2017 7:43 pm

distance Meter

Postby DavidMactavish » Sat Nov 04, 2017 7:00 am

Hi, man. I want a gauge or distance meter. :!: :!: :!: :!:
Whether this is face detection practical or not ?? :?: :?: :?:
Please give me the code. :roll: :roll:
Tanks. :) ;)
DavidMactavish
Posts: 14
Joined: Tue Sep 26, 2017 7:43 pm

Re: distance Meter

Postby DavidMactavish » Sat Nov 04, 2017 3:51 pm

DavidMactavish wrote:
Sat Nov 04, 2017 7:00 am
Hi, man. I want a gauge or distance meter. :!: :!: :!: :!:
Whether this is face detection practical or not ?? :?: :?: :?:
Please give me the code. :roll: :roll:
Tanks. :) ;)
Please help me
User avatar
kwagyeman
Posts: 1248
Joined: Sun May 24, 2015 2:10 pm

Re: distance Meter

Postby kwagyeman » Sat Nov 04, 2017 5:42 pm

Hi, can you give me some idea in a rather long write up what you need. The camera can kind of measure distance but not really.
Nyamekye,
DavidMactavish
Posts: 14
Joined: Tue Sep 26, 2017 7:43 pm

Re: distance Meter

Postby DavidMactavish » Sun Nov 05, 2017 1:15 am

kwagyeman wrote:
Sat Nov 04, 2017 5:42 pm
Hi, can you give me some idea in a rather long write up what you need. The camera can kind of measure distance but not really.
Hi, man. oh Yes.I want to display the distance between the object and the camera as an approximation in the face Detection :!: :?: :!: :?: :!:
If the distance was approximate. That's great :) ;) :) ;)
I want this distance meter on face Detection :)

tanks men.please help me :roll: :roll:
DavidMactavish
Posts: 14
Joined: Tue Sep 26, 2017 7:43 pm

Re: distance Meter

Postby DavidMactavish » Sun Nov 05, 2017 6:24 am

DavidMactavish wrote:
Sun Nov 05, 2017 1:15 am
kwagyeman wrote:
Sat Nov 04, 2017 5:42 pm
Hi, can you give me some idea in a rather long write up what you need. The camera can kind of measure distance but not really.
Hi, man. oh Yes.I want to display the distance between the object and the camera as an approximation in the face Detection :!: :?: :!: :?: :!:
If the distance was approximate. That's great :) ;) :) ;)
I want this distance meter on face Detection :)

tanks men.please help me :roll: :roll:
please Help me :roll:
User avatar
kwagyeman
Posts: 1248
Joined: Sun May 24, 2015 2:10 pm

Re: distance Meter

Postby kwagyeman » Sun Nov 05, 2017 2:02 pm

This kind of works. You get distances which are farther as the face gets smaller... and smaller as the face gets larger.

Please put some effort into using the system. I can't do the code for you. I was able to find a solution for this with very little effort by just googling for how to get the distance from a camera image.

Code: Select all

# Face Detection Example
#
# This example shows off the built-in face detection feature of the OpenMV Cam.
#
# Face detection works by using the Haar Cascade feature detector on an image. A
# Haar Cascade is a series of simple area contrasts checks. For the built-in
# frontalface detector there are 25 stages of checks with each stage having
# hundreds of checks a piece. Haar Cascades run fast because later stages are
# only evaluated if previous stages pass. Additionally, your OpenMV Cam uses
# a data structure called the integral image to quickly execute each area
# contrast check in constant time (the reason for feature detection being
# grayscale only is because of the space requirment for the integral image).

import sensor, time, image

lens_mm = 2.8 # Standard Lens.
average_head_height_mm = 232.0 # https://en.wikipedia.org/wiki/Human_head
image_height_pixels = 240.0 # QVGA
sensor_h_mm = 2.952 # For OV7725 sensor - see datasheet.
offest_mm = 100.0 # Offset fix...

# https://photo.stackexchange.com/questions/12434/how-do-i-calculate-the-distance-of-an-object-in-a-photo
def rect_size_to_distance(r): # r == (x, y, w, h) -> r[3] == h
    return ((lens_mm * average_head_height_mm * image_height_pixels) / (r[3] * sensor_h_mm)) - offest_mm

# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)

# FPS clock
clock = time.clock()

while (True):
    clock.tick()

    # Capture snapshot
    img = sensor.snapshot()

    # Find objects.
    # Note: Lower scale factor scales-down the image more and detects smaller objects.
    # Higher threshold results in a higher detection rate, with more false positives.
    objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25)

    # Draw objects
    for i in range(len(objects)):
        img.draw_rectangle(objects[i])
        print("Face %d -> Distance %d mm" % (i, rect_size_to_distance(objects[i])))
        
    img.draw_cross(img.width()//2, img.height()//2, size = min(img.width()//5, img.height()//5))

    # Print FPS.
    # Note: Actual FPS is higher, streaming the FB makes it slower.
    print("FPS %f" % clock.fps())
Nyamekye,
DavidMactavish
Posts: 14
Joined: Tue Sep 26, 2017 7:43 pm

Re: distance Meter

Postby DavidMactavish » Sun Nov 05, 2017 4:09 pm

kwagyeman wrote:
Sun Nov 05, 2017 2:02 pm
This kind of works. You get distances which are farther as the face gets smaller... and smaller as the face gets larger.

Please put some effort into using the system. I can't do the code for you. I was able to find a solution for this with very little effort by just googling for how to get the distance from a camera image.

Code: Select all

# Face Detection Example
#
# This example shows off the built-in face detection feature of the OpenMV Cam.
#
# Face detection works by using the Haar Cascade feature detector on an image. A
# Haar Cascade is a series of simple area contrasts checks. For the built-in
# frontalface detector there are 25 stages of checks with each stage having
# hundreds of checks a piece. Haar Cascades run fast because later stages are
# only evaluated if previous stages pass. Additionally, your OpenMV Cam uses
# a data structure called the integral image to quickly execute each area
# contrast check in constant time (the reason for feature detection being
# grayscale only is because of the space requirment for the integral image).

import sensor, time, image

lens_mm = 2.8 # Standard Lens.
average_head_height_mm = 232.0 # https://en.wikipedia.org/wiki/Human_head
image_height_pixels = 240.0 # QVGA
sensor_h_mm = 2.952 # For OV7725 sensor - see datasheet.
offest_mm = 100.0 # Offset fix...

# https://photo.stackexchange.com/questions/12434/how-do-i-calculate-the-distance-of-an-object-in-a-photo
def rect_size_to_distance(r): # r == (x, y, w, h) -> r[3] == h
    return ((lens_mm * average_head_height_mm * image_height_pixels) / (r[3] * sensor_h_mm)) - offest_mm

# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)

# FPS clock
clock = time.clock()

while (True):
    clock.tick()

    # Capture snapshot
    img = sensor.snapshot()

    # Find objects.
    # Note: Lower scale factor scales-down the image more and detects smaller objects.
    # Higher threshold results in a higher detection rate, with more false positives.
    objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25)

    # Draw objects
    for i in range(len(objects)):
        img.draw_rectangle(objects[i])
        print("Face %d -> Distance %d mm" % (i, rect_size_to_distance(objects[i])))
        
    img.draw_cross(img.width()//2, img.height()//2, size = min(img.width()//5, img.height()//5))

    # Print FPS.
    # Note: Actual FPS is higher, streaming the FB makes it slower.
    print("FPS %f" % clock.fps())




hi men.tanks , but I did not mean that.
I want to show the target distance to the camera at the same time as the number. Like this image
a.jpg
a.jpg (135.67 KiB) Viewed 154 times
asdwq.jpg
asdwq.jpg (178.84 KiB) Viewed 154 times
User avatar
kwagyeman
Posts: 1248
Joined: Sun May 24, 2015 2:10 pm

Re: distance Meter

Postby kwagyeman » Sun Nov 05, 2017 5:10 pm

The number is now printed on the screen. It's not going to look like what you want right now since we don't support face tracking with color images yet. There's no technical limit for this... the front end for parsing images during face tracking simply doesn't convert the image to grayscale yet.

Code: Select all

# Face Detection Example
#
# This example shows off the built-in face detection feature of the OpenMV Cam.
#
# Face detection works by using the Haar Cascade feature detector on an image. A
# Haar Cascade is a series of simple area contrasts checks. For the built-in
# frontalface detector there are 25 stages of checks with each stage having
# hundreds of checks a piece. Haar Cascades run fast because later stages are
# only evaluated if previous stages pass. Additionally, your OpenMV Cam uses
# a data structure called the integral image to quickly execute each area
# contrast check in constant time (the reason for feature detection being
# grayscale only is because of the space requirment for the integral image).

import sensor, time, image

lens_mm = 2.8 # Standard Lens.
average_head_height_mm = 232.0 # https://en.wikipedia.org/wiki/Human_head
image_height_pixels = 240.0 # QVGA
sensor_h_mm = 2.952 # For OV7725 sensor - see datasheet.
offest_mm = 100.0 # Offset fix...

# https://photo.stackexchange.com/questions/12434/how-do-i-calculate-the-distance-of-an-object-in-a-photo
def rect_size_to_distance(r): # r == (x, y, w, h) -> r[3] == h
    return ((lens_mm * average_head_height_mm * image_height_pixels) / (r[3] * sensor_h_mm)) - offest_mm

# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)

# FPS clock
clock = time.clock()

while (True):
    clock.tick()

    # Capture snapshot
    img = sensor.snapshot()

    # Find objects.
    # Note: Lower scale factor scales-down the image more and detects smaller objects.
    # Higher threshold results in a higher detection rate, with more false positives.
    objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25)

    # Draw objects
    for i in range(len(objects)):
        img.draw_rectangle(objects[i])
        img.draw_string(objects[i][0] - 16, objects[i][1] - 16, "Distance %d mm" % rect_size_to_distance(objects[i]))
        
    img.draw_cross(img.width()//2, img.height()//2, size = min(img.width()//5, img.height()//5))

    # Print FPS.
    # Note: Actual FPS is higher, streaming the FB makes it slower.
    print("FPS %f" % clock.fps())
Nyamekye,
DavidMactavish
Posts: 14
Joined: Tue Sep 26, 2017 7:43 pm

Re: distance Meter

Postby DavidMactavish » Sun Nov 05, 2017 6:24 pm

kwagyeman wrote:
Sun Nov 05, 2017 5:10 pm
The number is now printed on the screen. It's not going to look like what you want right now since we don't support face tracking with color images yet. There's no technical limit for this... the front end for parsing images during face tracking simply doesn't convert the image to grayscale yet.

Code: Select all

# Face Detection Example
#
# This example shows off the built-in face detection feature of the OpenMV Cam.
#
# Face detection works by using the Haar Cascade feature detector on an image. A
# Haar Cascade is a series of simple area contrasts checks. For the built-in
# frontalface detector there are 25 stages of checks with each stage having
# hundreds of checks a piece. Haar Cascades run fast because later stages are
# only evaluated if previous stages pass. Additionally, your OpenMV Cam uses
# a data structure called the integral image to quickly execute each area
# contrast check in constant time (the reason for feature detection being
# grayscale only is because of the space requirment for the integral image).

import sensor, time, image

lens_mm = 2.8 # Standard Lens.
average_head_height_mm = 232.0 # https://en.wikipedia.org/wiki/Human_head
image_height_pixels = 240.0 # QVGA
sensor_h_mm = 2.952 # For OV7725 sensor - see datasheet.
offest_mm = 100.0 # Offset fix...

# https://photo.stackexchange.com/questions/12434/how-do-i-calculate-the-distance-of-an-object-in-a-photo
def rect_size_to_distance(r): # r == (x, y, w, h) -> r[3] == h
    return ((lens_mm * average_head_height_mm * image_height_pixels) / (r[3] * sensor_h_mm)) - offest_mm

# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# HQVGA and GRAYSCALE are the best for face tracking.
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)

# FPS clock
clock = time.clock()

while (True):
    clock.tick()

    # Capture snapshot
    img = sensor.snapshot()

    # Find objects.
    # Note: Lower scale factor scales-down the image more and detects smaller objects.
    # Higher threshold results in a higher detection rate, with more false positives.
    objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25)

    # Draw objects
    for i in range(len(objects)):
        img.draw_rectangle(objects[i])
        img.draw_string(objects[i][0] - 16, objects[i][1] - 16, "Distance %d mm" % rect_size_to_distance(objects[i]))
        
    img.draw_cross(img.width()//2, img.height()//2, size = min(img.width()//5, img.height()//5))

    # Print FPS.
    # Note: Actual FPS is higher, streaming the FB makes it slower.
    print("FPS %f" % clock.fps())



Thank you so much men
That's what I wanted. :D :D
Thank you men ;)

Return to “General Topics”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests