From: Alex Leontiev Date: Fri, 19 Jul 2013 09:34:33 +0000 (+0300) Subject: Simplify printing procedures X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3823^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=33e7640fb07bedc47ececf580a21cfb8495ac087;p=platform%2Fupstream%2Fopencv.git Simplify printing procedures Use opencv's print() procedure in place of my own procedures to output matrices and std::vectors. Interestingly enough, operator<< does not work for matrices, when called from my .cpp files in src/ subfolder of the optim module, although it works when called from tests and stand-alone programs, compiled with opencv. I think, this requires investigation and, maybe, bug report. --- diff --git a/modules/optim/include/opencv2/optim.hpp b/modules/optim/include/opencv2/optim.hpp index 8443036..13ed865 100644 --- a/modules/optim/include/opencv2/optim.hpp +++ b/modules/optim/include/opencv2/optim.hpp @@ -44,7 +44,6 @@ #define __OPENCV_OPTIM_HPP__ #include "opencv2/core.hpp" -#include namespace cv{namespace optim { diff --git a/modules/optim/src/lpsolver.cpp b/modules/optim/src/lpsolver.cpp index 909794a..e746c39 100644 --- a/modules/optim/src/lpsolver.cpp +++ b/modules/optim/src/lpsolver.cpp @@ -12,20 +12,8 @@ using namespace std; #ifdef ALEX_DEBUG #define dprintf(x) printf x static void print_matrix(const Mat& x){ - printf("\ttype:%d vs %d,\tsize: %d-on-%d\n",x.type(),CV_64FC1,x.rows,x.cols); - if(!true){ - //cout<(i,j)); - } - printf("]\n"); - } - } + print(x); + printf("\n"); } static void print_simplex_state(const Mat& c,const Mat& b,double v,const std::vector N,const std::vector B){ printf("\tprint simplex state\n"); @@ -36,18 +24,14 @@ static void print_simplex_state(const Mat& c,const Mat& b,double v,const std::ve print_matrix(c); printf("non-basic: "); - for (std::vector::const_iterator it = N.begin() ; it != N.end(); ++it){ - printf("%d, ",*it); - } + print(Mat(N)); printf("\n"); printf("here b goes\n"); print_matrix(b); printf("basic: "); - for (std::vector::const_iterator it = B.begin() ; it != B.end(); ++it){ - printf("%d, ",*it); - } + print(Mat(B)); printf("\n"); } #else @@ -85,23 +69,8 @@ int solveLP(const Mat& Func, const Mat& Constr, Mat& z){ if(Func.rows==1){ Func.convertTo(bigC.colRange(1,bigC.cols),CV_64FC1); }else{ - dprintf(("hi from other branch\n")); - Mat_ slice=bigC.colRange(1,bigC.cols); - MatIterator_ slice_iterator=slice.begin(); - switch(Func.type()){ - case CV_64FC1: - for(MatConstIterator_ it=Func.begin();it!=Func.end();it++,slice_iterator++){ - * slice_iterator= *it; - } - break; - case CV_32FC1: - for(MatConstIterator_ it=Func.begin();it!=Func.end();it++,slice_iterator++){ - * slice_iterator= *it; - } - break; - } - print_matrix(Func); - print_matrix(bigC); + Mat FuncT=Func.t(); + FuncT.convertTo(bigC.colRange(1,bigC.cols),CV_64FC1); } Constr.convertTo(bigB.colRange(1,bigB.cols),CV_64FC1); double v=0; @@ -286,14 +255,9 @@ static int inner_simplex(Mat_& c, Mat_& b,double& v,vector& dprintf(("constraints\n")); print_matrix(b); dprintf(("non-basic: ")); - for (std::vector::iterator it = N.begin() ; it != N.end(); ++it){ - dprintf(("%d, ",*it)); - } - dprintf(("\nbasic: ")); - for (std::vector::iterator it = B.begin() ; it != B.end(); ++it){ - dprintf(("%d, ",*it)); - } - dprintf(("\n")); + print_matrix(Mat(N)); + dprintf(("basic: ")); + print_matrix(Mat(B)); } }