void myType1a() { const int LEN = 9; float value[LEN] = {-1.4, -8.8, -9.1, -2.7, -4.3, -1.5, -2.5, -3.5, -4.5}; //显示原始数据、绝对值、四舍五入 for(int i = 0; i<LEN; i++) { std::cout<<"value["<<i<<"]="<<value[i]<<"\t"; float tmp = fabs(value[i]); std::cout<<"|value["<<i<<"]|="<<tmp<<"\t"; std::cout<<"~value["<<i<<"]="<<cvRound(tmp)<<std::endl; } std::cout<<std::endl; CvMat mat = cvMat(3, 3, CV_32FC1, value); for(int col=0; col<mat.cols; col++) { for(int row=0; row<mat.rows; row++) { std::cout<<mat.data.fl[col+row*mat.cols]<<"\t"; } std::cout<<std::endl; } double min=0.f; double max=0.f; CvPoint min_loc=cvPoint(0, 0); CvPoint max_loc=cvPoint(0, 0); cvMinMaxLoc(&mat, &min, &max, &min_loc, &max_loc); std::cout<<"min="<<min<<"\tmin_loc=Point("<<min_loc.x<<","<<min_loc.y<<")"<<std::endl; std::cout<<"max="<<max<<"\tmax_loc=Point("<<max_loc.x<<","<<max_loc.y<<")"<<std::endl; }
《学习OpenCV(中文版)》第3章 练习1a
最新推荐文章于 2024-09-07 20:24:07 发布