Opencvノート
3294 ワード
OpenCVにおけるminMaxLocの使い方
関数のプロトタイプ:
void minMaxLoc( const Mat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, const Mat& mask=Mat() );
void minMaxLoc(const MatND& src, double* minVal, double* maxVal, int* minIdx=0, int* maxIdx=0, const MatND& mask=MatND() );
void minMaxLoc(const SparseMat& src, double* minVal, double* maxVal, int* minIdx=0, int* maxIdx=0);
説明:
1 minMaxLocは行列(一次元配列をベクトルとし、Matで定義)の中で最小値と最大値の位置を探す.
2パラメータが不要である、NULLまたは0とすればよい.
3 minMaxLocのMatとMatNDに対するリロードでは、5番目のパラメータはオプション(optional)である、使わずに渡さなければよい.
コード:Mat tmpCount(8, 1, CV_32FC1);
float tmpCountMinVal = 0, tmpCountMaxVal = 0;
Point minPoint, maxPoint;
minMaxLoc(tmpCount, &tmpCountMinVal, &tmpCountMaxVal, &minPoint, &maxPoint);
minMaxLoc(temp1, &minVal, NULL, &minCoor,NULL); // , NULL
cout<<minVal<<endl;
minMaxLoc(temp1, 0, &maxVal, 0,& maxCoor); // 0
cout<<maxVal<<endl;
結果:
10.9525 13.4054 17.6646 10.5643 1.22926 5.95938 11.14 4.83435
1.22926 17.6646
1.22926
17.6646
-------------------------------計時関数---------------------------------------------------
double t = (double)getTickCount();
t = ((double)getTickCount() - t)/getTickFrequency();
cout << "Times passed in seconds: "<< t << endl;
////API関数を呼び出してコンピュータの計時周波数を得ることで対応する時間を計算する
///
gettickFrequency()はコンピュータのタイミング周波数です
------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------double scale=0.5; //
string imageurl = "F:/opencv/samples/cpp/baboon.jpg";
Mat image =imread(imageurl);A
//
Size dsize = Size(image.cols*scale,image.rows*scale);
Mat image2 = Mat(dsize,CV_32S);
resize(image, image2,dsize);
----------------------------------------------------------------
------------------マトリクス内の複合要求の要素を選択--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Mat test=(Mat_<unsigned char>(10,1)<<1,2,3,4,5,6,7,8,9,10);
Mat b=(Mat_<unsigned char>(10,1)<<1,2,3,4,5,6,7,8,9,10);
test=test>5;
test=test/255;
cout<<test<<endl;
cout<<b<<endl;
int t1=test.type();// t1,t2
int t2=b.type();
Mat c(test.mul(b));
cout<<c<<endl;
---------------------------------------------------------------------------
Matタイプ変換
Mat a = Mat_ (10, 3);//またはMata=Mat_ (10, 3)
Mat_ b;
a.ConvertTo(b, CV_32F);
cout<<"a type"<
Mat tmpCount(8, 1, CV_32FC1);
float tmpCountMinVal = 0, tmpCountMaxVal = 0;
Point minPoint, maxPoint;
minMaxLoc(tmpCount, &tmpCountMinVal, &tmpCountMaxVal, &minPoint, &maxPoint);
minMaxLoc(temp1, &minVal, NULL, &minCoor,NULL); // , NULL
cout<<minVal<<endl;
minMaxLoc(temp1, 0, &maxVal, 0,& maxCoor); // 0
cout<<maxVal<<endl;
double scale=0.5; //
string imageurl = "F:/opencv/samples/cpp/baboon.jpg";
Mat image =imread(imageurl);A
//
Size dsize = Size(image.cols*scale,image.rows*scale);
Mat image2 = Mat(dsize,CV_32S);
resize(image, image2,dsize);
Mat test=(Mat_<unsigned char>(10,1)<<1,2,3,4,5,6,7,8,9,10);
Mat b=(Mat_<unsigned char>(10,1)<<1,2,3,4,5,6,7,8,9,10);
test=test>5;
test=test/255;
cout<<test<<endl;
cout<<b<<endl;
int t1=test.type();// t1,t2
int t2=b.type();
Mat c(test.mul(b));
cout<<c<<endl;
Mat_
a.ConvertTo(b, CV_32F);
cout<<"a type"<