Read the angle from a 360-degree meter


John

I have a meter that I have managed to extract using openCV . The white in the middle of the image of the meter in different positions is the needle, which can go from 0 to 360.

my code:

void readAngleOfMeter(Mat image, int number)
{
    cvtColor(image, image, COLOR_BGR2GRAY);
    inRange(image, Scalar(255, 255, 255), Scalar(255, 255, 255), image);

    vector<Vec2f> lines;
    HoughLines(tmp, lines, 1, CV_PI / 360, 30, 0, 0);

    if (lines.size() == 0) {
        cout << "No lines found" << endl;
        return;
    }

    float thetasum = 0;
    for (size_t i = 0; i < lines.size(); i++)
    {
        float theta = lines[i][1];
        thetasum += theta;
    }
    thetasum = thetasum / static_cast<int>(lines.size());
    cout << "Theta " << thetasum << endl;
}

My problem is now that I want to read the angle of the meter. So I thought about using the average angle of each line, but the problem is that it doesn't work because a line can be interpreted in two ways (eg 90 is the same as 270) and from 360 to 0.

Any ideas?

Mark Shecher

You don't even need to use the Hough transform. Write a loop that iterates from 0 to 360 in 1-degree increments, looking at the pixels in a circle centered at the center of the image. Remember the angle of the first white pixel, and when you find the next black pixel around the circle, take its angle and average it with the starting angle.

You may need to blur a little first or widen the gauge needle to fill in any gaps.

Try using a radius - a smaller radius will reduce the resolution of the needle as it looks thicker. A larger radius will give you higher resolution, but you risk missing the needle due to being thinner from the center.

Related


Read the angle from a 360-degree meter

John I have a meter that I have managed to extract using openCV . The white in the middle of the image of the meter in different positions is the needle, which can go from 0 to 360. my code: void readAngleOfMeter(Mat image, int number) { cvtColor(image, im

Read the angle from a 360-degree meter

John I have a meter that I have managed to extract using openCV . The white in the middle of the image of the meter in different positions is the needle, which can go from 0 to 360. my code: void readAngleOfMeter(Mat image, int number) { cvtColor(image, im

Read the angle from a 360-degree meter

John I have a meter that I have managed to extract using openCV . The white in the middle of the image of the meter in different positions is the needle, which can go from 0 to 360. my code: void readAngleOfMeter(Mat image, int number) { cvtColor(image, im

Read the angle from a 360-degree meter

John I have a meter that I have managed to extract using openCV . The white in the middle of the image of the meter in different positions is the needle, which can go from 0 to 360. my code: void readAngleOfMeter(Mat image, int number) { cvtColor(image, im

Read the angle from a 360-degree meter

John I have a meter that I have managed to extract using openCV . The white in the middle of the image of the meter in different positions is the needle, which can go from 0 to 360. my code: void readAngleOfMeter(Mat image, int number) { cvtColor(image, im

Read the angle from a 360-degree meter

John I have a meter that I have managed to extract using openCV . The white in the middle of the image of the meter in different positions is the needle, which can go from 0 to 360. my code: void readAngleOfMeter(Mat image, int number) { cvtColor(image, im

Read the angle from a 360-degree meter

John I have a meter that I have managed to extract using openCV . The white in the middle of the image of the meter in different positions is the needle, which can go from 0 to 360. my code: void readAngleOfMeter(Mat image, int number) { cvtColor(image, im

Get 360 degree angle

growler I want to get a 360 degree angle... For my game I need to know where the player is going... The code here gets the proper angles, but only in 90 degree increments: (i.e. when I click the upper left quadrant, I get an angle of 0 to 90 degrees... and the

Get 360 degree angle

growler I want to get a 360 degree angle... For my game I need to know where the player is going... The code here gets the proper angles, but only in 90 degree increments: (ie when I click on the upper left quadrant, I get an angle of 0 to 90 degrees... and th

360 degree angle

Swamp I coded this code here: double cosine = (v1.x*v2.x+v1.y*v2.y)/(150*150); double radian = Math.acos(cosine); double angle = Math.toDegrees(radian); V1 and V2 are two vectors which are simple Point(s)() for simplicity. Now I

Convert PyGame 2 axis joystick float to 360 degree angle

Archaeopteryx I want to convert the two axis float (horizontal and vertical) of the joystick into a 360 degree angle that can be used to set the player orientation in the game. From my research I found that the best way is to use Atan2. variable: self.rot = 0

Convert PyGame 2 axis joystick float to 360 degree angle

Archaeopteryx I want to convert the two axis float (horizontal and vertical) of the joystick into a 360 degree angle that can be used to set the player orientation in the game. From my research I found that the best way is to use Atan2. variable: self.rot = 0

How to display a 360 degree panorama from an Android app

Libathos I want to display a panorama from my android app, the panorama is online and I loaded its url on the webview but it's not working. It's just part of it, it doesn't turn or turn upside down. I don't know where to start, can you point me in the right di

OpenCV get 360 degree rotation from T-shaped body

Jonas Martinsson I am new to this forum and I hope you will be patient with me. I'm about to write my own vision system that will always track only one feature (pins) and will have trouble detecting my body orientation. I do get the orientation from the eigenv

OpenCV get 360 degree rotation from T-shaped body

Jonas Martinsson I am new to this forum and I hope you will be patient with me. I'm about to write my own vision system that will always track only one feature (pins) and will have trouble detecting my body orientation. I do get the orientation from the eigenv

360 degree rotation indicator

martinton I have a simple 360 image rotator that cycles through a series of images giving the effect of rotating an object. I want to add an indicator that shows the user an object that fades away after rotating past the fist image. So I added this function at

360 degree rotation indicator

martinton I have a simple 360 image rotator that cycles through a series of images giving the effect of rotating an object. I want to add an indicator that shows the user an object that fades away after rotating past the fist image. So I added this function at