Ask Your Question

N Samanwongthai's profile - activity

2015-11-14 23:15:05 -0600 answered a question Drawing Bounding Box

std::vector<cv::rect> detectObjects(cv::Mat img) { cv::Mat img_gray, img_sobel, img_threshold, element; Mat grad_x, grad_y; Mat abs_grad_x, abs_grad_y; cvtColor(img, img_gray, CV_BGR2GRAY); cv::Sobel(img_gray, img_sobel, CV_8U, 1, 0, 5, 1, 1, cv::BORDER_DEFAULT); cv::imshow("img_sobel", img_sobel); cv::threshold(img_sobel, img_threshold, 55, 255, CV_THRESH_OTSU + CV_THRESH_BINARY); cv::imshow("img_threshold", img_threshold); element = getStructuringElement(cv::MORPH_RECT, cv::Size(17,5)); cv::morphologyEx(img_threshold, img_threshold, MORPH_CLOSE, element); //Does the trick std::vector< std::vector< cv::Point> > contours; cv::findContours(img_threshold, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); std::vector<std::vector<cv::point> > contours_poly(contours.size()); std::vector<cv::rect> boundRect; for (int i = 0; i < contours.size(); i++) if (contours[i].size()>25) { cv::approxPolyDP(cv::Mat(contours[i]), contours_poly[i], 1, true); cv::Rect appRect(boundingRect(cv::Mat(contours_poly[i]))); //if (appRect.width>appRect.height) boundRect.push_back(appRect); } return boundRect; }

int main(){ src = imread("path\of\image",1); vector<cv::rect> letterBBoxes1 = detectObjects(src); //Display for (int i = 0; i< letterBBoxes1.size(); i++) cv::rectangle(src, letterBBoxes1[i], cv::Scalar(0, 255, 0), 3, 8, 0);

cv::imshow("src", src);

waitKey(0);
return 0;

}

code adapted from http://stackoverflow.com/questions/23...

2015-09-11 00:46:10 -0600 answered a question highgui missing in 3.0 release

Replace Highgui.imencode(".png", frame, buffer);

With Imgcodecs.imencode(".png", frame, buffer);