Opencv - polynomial function fitting -


in opencv (or other c++ lib), there similar function matlab fit can 3d polynomial surface fitting (i.e. f(x,y)= p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2). thanks

i don't think there lib in opencv can :

int main( int argc, char** argv ) { mat z    = imread("1449862093156643.jpg",cv_load_image_grayscale);  mat m = mat_<double>(z.rows*z.cols,6); mat i=mat_<double>(z.rows*z.cols,1); (int i=0;i<z.rows;i++)     (int j = 0; j < z.cols; j++)     {         double x=(j - z.cols / 2) / double(z.cols),y= (i - z.rows / 2) / double(z.rows);         m.at<double>(i*z.cols+j, 0) = x*x;         m.at<double>(i*z.cols+j, 1) = y*y;         m.at<double>(i*z.cols+j, 2) = x*y;         m.at<double>(i*z.cols+j, 3) = x;         m.at<double>(i*z.cols+j, 4) = y;         m.at<double>(i*z.cols+j, 5) = 1;         i.at<double>(i*z.cols+j, 0) = z.at<uchar>(i,j);     } svd s(m); mat q; s.backsubst(i,q); cout<<q; imshow("orignal",z); cout<<q.at<double>(2,0); mat background(z.rows,z.cols,cv_8uc1); (int i=0;i<z.rows;i++)     (int j = 0; j < z.cols; j++)     {         double x=(j - z.cols / 2) / double(z.cols),y= (i - z.rows / 2) / double(z.rows);         double quad=q.at<double>(0,0)*x*x+q.at<double>(1,0)*y*y+q.at<double>(2,0)*x*y;         quad+=q.at<double>(3,0)*x+q.at<double>(4,0)*y+q.at<double>(5,0);         background.at<uchar>(i,j) = saturate_cast<uchar>(quad);     } imshow("simulated background",background); waitkey(); return 0; } 

original post here


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -