วันอาทิตย์ที่ 15 มกราคม พ.ศ. 2560

C++ opencv Line Table


#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;

int main(int argc, char** args)
{
Mat src = imread("D:\\1213.jpg");
cvtColor(src, src, CV_BGR2GRAY);

Rect croppedRectangle = Rect(550, 400, 150, 255);
Mat croppedImage = src(croppedRectangle);

vector<vector<cv::Point>> contours;
vector<Vec4i> hierarchy;

Canny(src, src, 100, 200, 3);
//imshow("dda", src);

findContours(croppedImage, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

Mat drawing = Mat::zeros(croppedImage.size(), CV_8UC3);
char text[200] = " ";
//CvFont font = cvFont(2, 2);

for (int i = 0; i < contours.size(); i++)
{
drawContours(drawing, contours, i, CV_RGB(255, 0, 0), 1, 8, hierarchy, 0, Point());
cv::Rect brect = cv::boundingRect(contours[i]);
if (brect.area() < 1000)
continue;
sprintf(text, "S = %d", brect.area());
putText(drawing, text, cvPoint(brect.x+20, brect.y+20), 1, 1, CV_RGB(0, 255, 0));
rectangle(drawing, brect, CV_RGB(0, 0, 255), 2);
}
imshow("dd", drawing);
waitKey(0);
destroyAllWindows();
return 0;
}


ไม่มีความคิดเห็น:

แสดงความคิดเห็น