|
Tài trợ cho PIC Vietnam |
Xử lý ảnh Các thuật toán xử lý ảnh dùng trong robot |
|
Ðiều Chỉnh | Xếp Bài |
29-08-2014, 12:14 PM | #3 |
Nhập môn đệ tử
Tham gia ngày: Nov 2013
Bài gửi: 4
: |
Cho bạn cái hàm để bạn tham khảo
int FindPlate() { Mat src1 = imread("images\\BienSo.jpg", CV_LOAD_IMAGE_COLOR); if(!src1.data) return 0; Mat src2 = src1.clone(); // copy anh Mat gray, binary; cvtColor(src1, gray, CV_BGR2GRAY); threshold(gray, binary, 100, 255, CV_THRESH_BINARY); imshow("Anh nhi phan goc", binary); Mat morpho; Mat element = getStructuringElement(MORPH_CROSS, Size(3,3), Point(1,1)); erode(binary, morpho, element, Point(-1,-1), 3); imshow("Anh sau khi thuc hien phep gian no", morpho); vector<vector<Point> > contours1; findContours(binary, contours1, CV_RETR_LIST, CV_CHAIN_APPROX_NONE ); for(size_t i = 0; i < contours1.size(); i++) { Rect r = boundingRect(contours1[i]); if(r.width/(double)r.height > 3.5f && r.width/(double)r.height < 4.5f) rectangle(src1, r, Scalar(0, 0, 255), 2, 8, 0); else rectangle(src1, r, Scalar(0, 255, 0), 1, 8, 0); } imshow("Ket qua phat hien truoc phep gian no", src1); vector<vector<Point> > contours2; findContours(morpho, contours2, CV_RETR_LIST, CV_CHAIN_APPROX_NONE ); for(size_t i = 0; i < contours2.size(); i++) { Rect r = boundingRect(contours2[i]); if(r.width/(double)r.height > 3.5f && r.width/(double)r.height < 4.5f) rectangle(src2, r, Scalar(0, 0, 255), 2, 8, 0); else rectangle(src2, r, Scalar(0, 255, 0), 1, 8, 0); } imshow("Ket qua phat hien sau khi phep gian no", src2); } |
|
|