Problem with Sobel

General discussion about topics related to OpenMV.
bmi262
Posts: 4
Joined: Sun Oct 21, 2018 9:02 pm

Problem with Sobel

Postby bmi262 » Sun Oct 21, 2018 9:39 pm

Hello.
I have a project with OpenMV M7.This project is used Sobel to get edge.I use morph to build Sobel.But I found this function takes up a lot of resources and can't get a good result.I found some function used Sobel.
Can you help me?Thank you.
User avatar
kwagyeman
Posts: 2401
Joined: Sun May 24, 2015 2:10 pm

Re: Problem with Sobel

Postby kwagyeman » Sun Oct 21, 2018 9:44 pm

Hi, can you post your code? Note that general purpose convolutions take up a lot of CPU.
Nyamekye,
bmi262
Posts: 4
Joined: Sun Oct 21, 2018 9:02 pm

Re: Problem with Sobel

Postby bmi262 » Sun Oct 21, 2018 9:52 pm

# Untitled - By: bmi

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()


#sobel
kernel_size = 1
kernel_x = [-1, 0, +1,\
-2, 0, +2,\
-1, 0, +1]
kernel_y = [-1, -2, -1,\
0, 0, 0,\
+1, +2, +1]

while(True):
clock.tick()
img = sensor.snapshot()
tempy = img.bilateral(1)

sobel_x = img.morph(kernel_size, kernel_x)
sobel_y = tempy.morph(kernel_size, kernel_y)
sobel = sobel_y.add(sobel_x)

print(clock.fps())

This is my code. I know this code have a problem.Sobel formula is G = |Gx| + |Gy|.But I didn't find absolute function.
User avatar
kwagyeman
Posts: 2401
Joined: Sun May 24, 2015 2:10 pm

Re: Problem with Sobel

Postby kwagyeman » Sun Oct 21, 2018 10:08 pm

I see what you are trying to do... um, you can't really do this with the OpenMV Cam however. This is because you need an output buffer for each sobel method.

Um, what do you want to do with the sobel image? If you just need the magnitude then you can do: https://en.wikipedia.org/wiki/Kernel_(image_processing)

Our find_lines() method runs this kinda of thing internally all in C and collects the result. What is the end application?
Nyamekye,
bmi262
Posts: 4
Joined: Sun Oct 21, 2018 9:02 pm

Re: Problem with Sobel

Postby bmi262 » Sun Oct 21, 2018 10:55 pm

I want to use Sobel to find elliptical or circular fuzzy edges.
User avatar
kwagyeman
Posts: 2401
Joined: Sun May 24, 2015 2:10 pm

Re: Problem with Sobel

Postby kwagyeman » Sun Oct 21, 2018 11:53 pm

Um, is find_circles() not enough? If so, then you have to do this in C. Or, alternatively, allocate two image buffers (see the sensor module for allocing a second buffer) and then copy the snapshot into the second buffer and sobel each with a different gradient. That said, you're not going to be able to process the images quick enough in python.
Nyamekye,
bmi262
Posts: 4
Joined: Sun Oct 21, 2018 9:02 pm

Re: Problem with Sobel

Postby bmi262 » Mon Oct 22, 2018 1:12 am

Thank you.I will try it.

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 1 guest