-2

Here is a code where I want to implement the object measurement, but I don't have any idea on what function that I've to use and how to code it and how to make it auto generate. There's anyone can help me? Thank you in advanced.


cv::VideoCapture cap;

if (!cap.isOpened())  // check if succeeded to connect to the camera
    CV_Assert("Can't open Web-Cam");

double CamHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
double CamWidth  = cap.get(CV_CAP_PROP_FRAME_WIDTH);

//Display text on the screen function
int imgW = 650;
int imgH = 50;
int fontFace = FONT_HERSHEY_PLAIN;
double fontScale = 1.5;
int thickness = 2;
Point textOrg(imgW/5, imgH/1.3);

int value=10;
string someText = format("Dimension: %d ", value); //Display the dimension (output)
putText(frame, someText, textOrg, fontFace, fontScale, Scalar::all(255), thickness, 8);
imshow("Object Measurement",frame);;
  • can you explain what is meant by "measurement on object"? maybe you can give a concrete example? – Micka May 28 '14 at 07:07

1 Answers1

1

This code is about putting text onto some image.

Where did you initialize frame ?

Where is the main loop that gets frames ?

In general you use while(waitKey(someMiliseconds) != someValue) to break the loop that gets frames and processes them, with a keyboard button. If you dont use waitKey, windows are closed instantly.

About object measurement, for pixelwise measurement you need to utilize methods like findContours, boundingRect. Tutorial is on this link. For real world dimensions, you need to calibrate your camera, use intrinsic (focal lengths, distortions) and extrinsic (depth of the object) parameters to reconstruct real world coordinates. With depth information, you can extract real dimensions (and vice versa).

In short, you cannot "auto-generate" 3D reconstruction and measurement with only one camera, unless the depth of the object is assumed constant. O.w., user should enter the depth.

You can utilize another camera to "auto-generate" with stereo vision.

Community
  • 1
  • 1
baci
  • 2,528
  • 15
  • 28