# How to center the scrapper using data from image processing and XY stepper motor

So, I have successfully created a formula to scrape the coconut in a spherical fashion according to the radius of the coconut, however, there's just this one problem.

For some reason, some of the coconuts that has been scrapped didn't start from the center and instead determined that the center is in the upper left side of the coconut. Now I already had a function for placing the holder at the center before the program starts, but it seems that wasn't enough.

I needed to create a function that can take the center of the coconut and adjust it according to where the scrapper is. I already had the resolution of the image already set as a fixed variable, and the program can send the center coordinates of the coconut from the image from the Raspberry Pi to the Arduino. Though I have yet to acquire the full values of the stepper motor from one end of the corner to another, I would be able to do this, though minor help will be needed.

With all of the values set and acquired, how am I going to create the function of centering the coconut to the center of the scrapper?

English is not my native language, and I don't have the faintest idea what you are trying to build

What's the purpose of the stepper motor? What's the scrapper supposed to do?

A picture or CAD plan of your construction were helpful. And an image of the coconut as taken on the RasPi, with indication of the marks used in your calculation.

Here are the images of the Machine for context:

Your photos don't show what the stepper motor(s) is(are) doing.

I needed to create a function that can take the center of the coconut and adjust it according to where the scrapper is.

If you know the X and Y positions of the scraper (note the spelling, only one p) and you know (from the image) the X and Y positions of the centre of the coconut then the maths should be straightforward. What, exactly are you having trouble with?

...R

PS ... The word "scrapper" means a person involved in a scrap which is a minor fight or quarrel.

And an image of the coconut as taken on the RasPi,

Where was that?

set as a fixed variable

No such thing, you either have a variable of a constant.

how am I going to create the function of centering the coconut to the center of the scrapper?

This is a simple translation problem to give it the proper mathematical name for the function you want. You have to add an x and y offset given by the scraper’s position to the centre coordinates of coconut.

For some reason, some of the coconuts that has been scrapped didn't start from the center and instead determined that the center is in the upper left side of the coconut.

That is image processing for you, it is picking up on the wrong thing. What your real problem is that your image processing algorithm for finding the centre is not working reliably enough. That is what you really need help with. I am assuming you are using openCV on the Raspberry Pi, what version is it? Is it the latest one.
A big part of making computer vision reliable is the consistency of the lighting.

Robin2:
Your photos don't show what the stepper motor(s) is(are) doing.

I'll explain:

The X and Y stepper motors are used to move the coconut along the scraper, which is at the other end of the machine, in a radial manner, which is done in layers as the size dynamically increases, which resulted to a spherical shape.

The Z motor is responsible for bringing the coconut to the other end of the machine (to the scraper).

Robin2:
If you know the X and Y positions of the scraper (note the spelling, only one p) and you know (from the image) the X and Y positions of the center of the coconut then the maths should be straightforward. What, exactly are you having trouble with?

Well, after I had centered the coconut in a mechanical manner through code and after the scraping function, the coconuts all ended up having the shredding start at the upper left part of the coconut instead of the center, which happened twice during testing.

Grumpy_Mike:
Where was that?

Look at the Camera in the second picture

Grumpy_Mike:
No such thing, you either have a variable of a constant.

Yep, my bad. I was suppose to say a variable.

Grumpy_Mike:
This is a simple translation problem to give it the proper mathematical name for the function you want. You have to add an x and y offset given by the scraper's position to the centre coordinates of coconut.

And how do I possibly do that? Or at least, how do I start making such a function?

Grumpy_Mike:
That is image processing for you, it is picking up on the wrong thing. What your real problem is that your image processing algorithm for finding the centre is not working reliably enough. That is what you really need help with. I am assuming you are using openCV on the Raspberry Pi, what version is it? Is it the latest one.
A big part of making computer vision reliable is the consistency of the lighting.

That happened after the center adjustments are made mechanically, so I knew there was a problem in the mechanical aspect, though I thought about making adjustments to the mechanical centering function through the code.

Though I could use some minor help in regards to the image processing, that's for sure.

it_master:
Well, after I had centered the coconut in a mechanical manner through code and after the scraping function, the coconuts all ended up having the shredding start at the upper left part of the coconut instead of the center, which happened twice during testing.

I don't understand. Do you have a photo to illustrate the problem - or maybe a short YouTube video

Maybe you could make a simple pencil diagram showing how the machine is intended to work and post a photo of the drawing.

Is the coconut rotating, or is it only the scraper that rotates?

...R

Look at the Camera in the second picture

No what you were being asked is for what that camera is seeing not a photograph of the camera itself.

And how do I possibly do that?

What do an addition operation? Use the + function. That to me is what you are asking for. Now obviously you are not because you know how to add variables together. So what do you mean here? A function is simply an arithmetic operation.

Remember you know what the problem is because you have it in front of you and in your head. We only know what you are telling us and so far it is not too clear.