1 #ifndef __IMAGECLUSTER_UTILITIES_CXX__
2 #define __IMAGECLUSTER_UTILITIES_CXX__
5 #include <opencv2/imgproc/imgproc.hpp>
13 throw larbys(
"Cannot create SubMatrix for a contour of size < 2!");
20 for(
auto const& pt : cluster) {
22 if(pt.x < x_min) x_min = pt.x;
23 if(pt.x > x_max) x_max = pt.x;
24 if(pt.y < y_min) y_min = pt.y;
25 if(pt.y > y_max) y_max = pt.y;
29 return ::cv::Rect( x_min, y_min,
37 throw larbys(
"Cannot create SubMatrix for a contour of size < 2!");
42 img(bbox).copyTo(result);
50 throw larbys(
"Cannot create SubMatrix for a contour of size < 2!");
54 ::cv::Mat result = ::cv::Mat::zeros(img.size(),img.type());
56 for(
int x=0; x<img.rows; ++x) {
58 for(
int y=0; y<img.cols; ++y) {
60 int submat_x = x - bbox.x;
61 int submat_y = y - bbox.y;
63 double inside = ::cv::pointPolygonTest(cluster,::cv::Point2f(x,y),
false);
65 if(inside<0)
continue;
67 result.at<
float>(submat_x,submat_y,0) = img.at<
float>(x,y,0);