main_hist.cpp
// NCC classifier
// Where x is the value to compare, m is the points to compare and names is the labels of the points, max_thresh is the maximum threhold
// Returns the label of the point with the nearest center
NCC classifier
Where x is the value to compare, m is the points to compare and names is the labels of the points, max_thresh is the maximum threhold
Returns the label of the point with the nearest center
NCC classifier Where x is the value to compare m is the points to compare and names is the labels of the points max_thresh is the maximum threhold Returns the label of the point with the nearest center
std::string ncc(const cv::Mat &x, const cv::Mat &m, const std::vector<std::string> &names, const float &max_thresh = 2*std::pow(10,20)){
    double v_min, v_max;
    int idx_min[2] = {255,255}, idx_max[2] = {255, 255};
    cv::Mat d = cv::Mat::zeros(m.cols, 1, CV_32F);
    for(int i = 0; i < m.cols; i++)
    {
        d.row(i) = (x.t() * m.col(i) - 0.5*m.col(i).t()*m.col(i));
    }
    cv::minMaxIdx(d, &v_min, &v_max, idx_min, idx_max);
    if(max_thresh < v_max)
    {
        std::cout << "Would have returned " << names[idx_max[0]] << " but v_max = " << v_max << std::endl;
        return "unknown";
    }else{
        return names[idx_max[0]];
    }
}
std :: string ncc ( const cv :: Mat & x , const cv :: Mat & m , const std :: vector < std :: string > & names , const float & max_thresh = 2 * std :: pow ( 10 , 20 ) ) { double v_min , v_max ; int idx_min [ 2 ] = { 255 , 255 } , idx_max [ 2 ] = { 255 , 255 } ; cv :: Mat d = cv :: Mat :: zeros ( m . cols , 1 , CV_32F ) ; for ( int i = 0 ; i < m . cols ; i ++ ) { d . row ( i ) = ( x . t ( ) * m . col ( i ) - 0.5 * m . col ( i ) . t ( ) * m . col ( i ) ) ; } cv :: minMaxIdx ( d , & v_min , & v_max , idx_min , idx_max ) ; if ( max_thresh < v_max ) { std :: cout << " " << names [ idx_max [ 0 ] ] << " " << v_max << std :: endl ; return " " ; } else { return names [ idx_max [ 0 ] ] ; } }
NCC classifier
Where x is the value to compare, m is the points to compare and names is the labels of the points, max_thresh is the maximum threhold
Returns the label of the point with the nearest center
NCC classifier Where x is the value to compare m is the points to compare and names is the labels of the points max_thresh is the maximum threhold Returns the label of the point with the nearest center
//each row is a result // Hypothetically this should be a single operation, but I'm hoping that C++ is fast enough that I won't notice. //std::cout << "FOR" << std::endl; //std::cout << "x shape " << x.t().size() << " m shape " << m.col(i).size() << std::endl; //std::cout << "d" << d << std::endl; //std::cout << "MAX" << std::endl; //std::cout << "idx_min=" << idx_min[0] << ", idx_max=" << idx_max[0] << std::endl; //std::cout << "accessing index " << idx_max[0] << " names length " << names.size() << std::endl;