OneObjectRow::OneObjectRow(ContourFamily cont_fam,const cv::Mat& raw_img): m_n_in_clust(cont_fam.n_per_clust),m_valid(true),m_ROI(1) { m_rrect = cv::minAreaRect(cont_fam.contours[0]); m_rad = Features::calculateWH(cont_fam.contours[0]).x; cv::Rect rect = cv::boundingRect(cont_fam.contours[0]); cv::Mat mini_mask(rect.height,rect.width,CV_8UC1,cv::Scalar(0)); cv::Mat mini_img; raw_img(rect).copyTo(mini_img); cv::drawContours(mini_mask,cont_fam.contours,0,cv::Scalar(255),-1,8, cont_fam.hierarchies, 2, cv::Point(-rect.x,-rect.y)); cv::Mat mean, stddev; cv::meanStdDev(mini_img, mean, stddev, mini_mask); m_area = cv::countNonZero(mini_mask); stddev +=1; m_BGR_mean = mean.at<cv::Scalar>(0,0); m_BGR_sd = stddev.at<cv::Scalar>(0,0); cv::Mat one_pix(1,1,CV_8UC3,m_BGR_mean); cv::cvtColor(one_pix,one_pix,CV_BGR2HLS); cv::Scalar mean_sc = cv::mean(one_pix); //? m_hue_mean =((int) mean_sc [0])*2; m_sat_mean = (int) mean_sc [2]; }
std::vector<bool> Step_FiltHS::filter(const Result& in_numerical_result){ std::vector<bool> valid(in_numerical_result.size(),true); for(unsigned int i = 0; i < valid.size(); i++){ const OneObjectRow& oor = in_numerical_result.getRow(i); cv::Scalar mean = oor.getBGRMean(); cv::Mat one_pix(1,1,CV_8UC3,mean); cv::cvtColor(one_pix,one_pix,CV_BGR2HLS); mean = cv::mean(one_pix); int mean_hue =((int) mean[0])*2; float aa = (float) mean_hue * 3.1416 /180; float bb = (float) m_centr_hue * 3.1416 /180; int diff = abs(atan2(sin(aa-bb), cos(aa-bb)) * 180 / 3.1416); int mean_sat = (int) mean[2]; if(diff > m_tol_hue || mean_sat > m_max_sat || mean_sat < m_min_sat) valid[i] = false; else valid[i] = oor.isValid(); } return valid; }