Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:28:08+00:00 2026-06-16T03:28:08+00:00

I have to find the ruler position from an image by using opencv.I am

  • 0

I have to find the ruler position from an image by using opencv.I am able to detect the color of the ruler(green). How can i read all the pixel from an image and get the upper and lower position of ruler.

void findrulerPosition(cv::Mat image, int indx) {
std::stringstream ss;//create a stringstream
ss << indx;//add number to the stream

cv::Mat hsv;
cvtColor(image, hsv, CV_BGR2HSV);

String filename = OUTPUT_FOLDER + "hsv" + ss.str() + ".png";
imwrite(filename, hsv );

cv::Mat hsvbw;
inRange(hsv, cv::Scalar(30,0,0), cv::Scalar(80, 255, 255), hsvbw);
//inRange(hsv, cv::Scalar(12,255,255), cv::Scalar(23, 245, 255), hsvbw);
   //inRange(image, cv::Scalar(0,64,255), cv::Scalar(0, 207, 255), hsvbw);

filename = OUTPUT_FOLDER + "hsvbw" + ss.str() + ".png";
imwrite(filename, hsvbw );


vector<vector<Point> > contours;
findContours(hsvbw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
cv::Mat dst = Mat::zeros(image.size(), image.type());
drawContours(dst, contours, -1, Scalar::all(255), CV_FILLED);

this->cmpddst &=  dst;
dst &= image;
this->cmpddst &=  image;

filename = OUTPUT_FOLDER + "cmpddst" + ss.str() + ".png";
imwrite(filename, this->cmpddst );


filename = OUTPUT_FOLDER + "dst" + ss.str() + ".png";
imwrite(filename, dst );

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:28:10+00:00Added an answer on June 16, 2026 at 3:28 am

    Here’s what I’ve done:

    1. A bit improved your green range because yours is not detecting green color – it’s detecting many other colors.
    2. Find contours on image.
    3. Find contour with area bigger than 100.
    4. Find up and low points of contour.
    5. Draw these 2 points.
    Mat src = imread("input.png"), tmp;
    cvtColor(src, tmp, CV_BGR2HSV_FULL);
    inRange(tmp, Scalar(50, 50, 50), Scalar(70, 255, 255), tmp);
    
    vector<vector<Point> > contours;
    findContours(tmp, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    
    int upY = INT_MAX, lowY = 0, upX, lowX;
    for (int i=0; i<contours.size(); i++)
    {
        if (contourArea(contours[i]) > 100)
        {
            for (int j=0; j<contours[i].size(); j++)
            {
                if (contours[i][j].y > lowY)
                {
                    lowY = contours[i][j].y;
                    lowX = contours[i][j].x;
                }
                if (contours[i][j].y < upY)
                {
                    upY = contours[i][j].y;
                    upX = contours[i][j].x;
                }
            }
    
            cout << "low = (" << lowX << ", " << lowY << ")"<<  endl
                 << "up  = (" << upX << ", " << upY << ")"<<  endl;
            break;
        }
    }
    
    circle(src, Point(lowX, lowY), 3, Scalar(255, 0, 255));
    circle(src, Point(upX, upY), 3, Scalar(255, 0, 255));
    
    imshow("Window", src);
    waitKey();
    

    Here’s result:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Find function in order to find an element from a BST
I have to find some patters from a XML file, but i am unable
Is there a way to select all elements that have a given style using
For my application I have to find the position of a point on Google
I have tried using CSS to set the position of the background and the
I am evaluating datamining packages. I have find these two so far: RapidMiner Weka
i have to find the shortest distance between the railway stations- given is the
I have a list of words and i have to find the minimum word
I have an xml file in which I have to find patterns and put
I started to learn PHP and have to find a mistake (maybe in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.