i need help to achieve measuring the size of objects using OpenCV.
I got a Link for this functionality, but it was done in Python.I have tried to convert in C++ & Python too but could n't achieve. Honestly i don't know C++ i was tried below code.I am trying to implement this functionality in iOS app.
- (void)processImage:(cv::Mat &)image;
{
Mat gray;
cvtColor(image, gray, CV_BGRA2GRAY);
cv::GaussianBlur(gray, gray, cvSize(7, 7), 0);
cv::Canny(gray, gray, 50, 100);
cv::dilate(gray, gray, NULL);
cv::erode(gray, gray, NULL);
cv::findContours(gray, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
//sort the contours from left-to-right and initialize the 'pixels per metric' calibration variable
sort(contours.begin(), contours.end(), [](const vector<cv::Point>& c1, const
vector<cv::Point>& c2){
return contourArea(c1, false) < contourArea(c2, false);
});
for(int i=0; i<contours.size(); i++)
{
if (contourArea(contours[i]) < 100) {
break;
}
std::vector<cv::Point2f> boxPts;
gray.copyTo(orig);
box = minAreaRect(contours[i]);
cv::boxPoints(box, boxPts);
// here i got freeze 'numpy',np i don't know exactly what's this can't move forward
// box = np.array(box, dtype="int")
}
}
Can someone help me to doing this functionality in C++. If anyone other c++ source/link is available for this functionality kindly share with me.Thanks in advance