这篇教程C++ threshold函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中threshold函数的典型用法代码示例。如果您正苦于以下问题:C++ threshold函数的具体用法?C++ threshold怎么用?C++ threshold使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了threshold函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: getOrdervector<int> FRID::getFeaturePoints(){ int i,j; vector<int> r; uint _order = getOrder(); int sz=w4*h4; Mat sobelx, gradx, sobely,grady,sobel; Mat sobelgray_,sobelgray__,sobelgray; int totalPoints; Sobel(orderMap[_order],sobelx,CV_16S,1,0,3,1, 0, BORDER_DEFAULT ); convertScaleAbs( sobelx, gradx ); Sobel(orderMap[_order],sobely,CV_16S,0,1,3,1, 0, BORDER_DEFAULT ); convertScaleAbs( sobely, grady ); addWeighted( gradx, 0.5, grady, 0.5, 0, sobel ); cvtColor(sobel,sobelgray_,CV_RGB2GRAY); sobelgray_.convertTo(sobelgray__,CV_8UC1); double min,max; int maxid[2]; minMaxIdx(sobelgray__,&min,&max,0,maxid); threshold(sobelgray__,sobelgray__,(int)(((float)max)/255*100),1,THRESH_BINARY); totalPoints = sum(sobelgray__)[0]; cout<<"max: "<<max<<endl; cout<<"totalPoints: "<<totalPoints<<endl; double br; double bg; double bb; double bsr; double bsg; double bsb; int xmin,xmax,ymin,ymax; //Mat bufABSmat; //Mat bufABS2mat; Mat result1; Mat cdmat; orderMap[_order].copyTo(cdmat); for (i=0; i<sz; i++){ if (sobelgray__.at<uchar>(i/w4,i%w4) == 0) continue; float* bufABS = getFeatureVector(i%w4,i/w4,br,bg,bb,bsr,bsg,bsb); Mat bufABSmat ((_order/2-1)*3+3,1,CV_32FC1,bufABS); //bufABSmat; Mat corImg = Mat::zeros(Size(w4,h4),CV_8UC1); xmin=w4-1,xmax=0,ymin=h4-1,ymax=0; for (j=0; j<sz; j++){ if (sobelgray__.at<uchar>(j/w4,j%w4) == 0) continue; float* bufABS2 = getFeatureVector(j%w4,j/w4,br,bg,bb,bsr,bsg,bsb); Mat bufABS2mat ((_order/2-1)*3+3,1,CV_32FC1,bufABS2); matchTemplate(bufABSmat, bufABS2mat, result1, CV_TM_CCOEFF_NORMED); if (bsr>255 && bsg>255 && bsb>255 && pow(result1.at<float>(0),3)>0.5) { if (xmin > j%w4) xmin = j%w4; if (xmax < j%w4) xmax = j%w4; if (ymin > j/w4) ymin = j/w4; if (ymax < j/w4) ymax = j/w4; corImg.at<uchar>(j) = 1;//(result1.at<float>(0) > 0)? pow(result1.at<float>(0),10):0; if ((xmax-xmin)>6 && (ymax-ymin)>6)break; } }// namedWindow( "c", CV_WINDOW_AUTOSIZE );// imshow( "c", corImg*255);//thrCrCb[0] );//// waitKey(0); if ((xmax-xmin)<=6 && (ymax-ymin)<=6) { cout<<"xy: "<<i%w4<<", "<<i/w4<<endl; cout<<"totalPoints: "<<sum(sobelgray__)[0]<<endl; circle( cdmat, Point(i%w4,i/w4), 1, Scalar( 0, 0, 255 ), -1, 8 ); r.push_back(i%w4); r.push_back(i/w4); } //sobelgray__=sobelgray__-corImg; } //circle( cdmat, Point(maxid[1],maxid[0]), 1, Scalar( 0, 0, 255 ), -1, 8 ); return r;}
开发者ID:Nicatio,项目名称:Nicatio,代码行数:92,
示例2: thresholdvoid ThresholdWindow::on_sizeSpinBox_valueChanged(int){ threshold();}
开发者ID:manuelnaranjo,项目名称:ImageQ,代码行数:4,
示例3: imageCb void imageCb(const sensor_msgs::ImageConstPtr& msg) { ros::Time start = ros::Time::now(); cv_bridge::CvImagePtr cv_ptr; try { cv_ptr = cv_bridge::toCvCopy(msg, enc::BGR8); } catch (cv_bridge::Exception& e) { ROS_ERROR("cv_bridge exception: %s", e.what()); return; } // function call threshold_frame = threshold(cv_ptr->image); // MORPH_ELLIPSE=2 cv::Mat kernel = cv::getStructuringElement(2, cv::Size( 3, 3 ), cv::Point( -1, -1 )); // Dilate the image cv::dilate(threshold_frame, dilated, kernel, cv::Point(-1,-1), 5); // Erode the image cv::erode(dilated, eroded, kernel, cv::Point(-1,-1), 2); clone_eroded = eroded.clone(); std::vector< std::vector<cv::Point> > contours; // storage for the contours std::vector<cv::Vec4i> hierarchy; // hierachy // for saving the result frame //origin_result = result.clone(); // for saving the eroded frame200 clone_eroded = eroded.clone(); // just get the contours // using clone_eroded image cv::findContours( clone_eroded, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0,0) ); int no_ellipse(0); for( int i(0); i< (contours.size()); i++ ) { if( contours[i].size() < 50 ) continue; cv::drawContours( cv_ptr->image, contours, i, cv::Scalar(255,0,0), 1, 8 ); cv::Moments moms = cv::moments( cv::Mat(contours[i])); double area = moms.m00; double perimeter = cv::arcLength(cv::Mat(contours[i]),true); double circularity = 4*CV_PI*area/(perimeter*perimeter); if( circularity > 0.3 ) { cv::RotatedRect ellipse_candidate = cv::fitEllipse( cv::Mat(contours[i]) ); cv::ellipse( cv_ptr->image, ellipse_candidate, cv::Scalar(0,255,0), 2, 8 ); no_ellipse ++; // radius -> {(W+H)/2}/2 double radius_i = (ellipse_candidate.size.height+ellipse_candidate.size.width)/4; //std::cout << "height : " << std::setw(7) << ellipse_candidate.size.height // << " " << "width : " << std::setw(7) << ellipse_candidate.size.width // << " " << "radius : " << radius_i << std::endl; double f= 700; dist = 3 * f / radius_i; printf("R | Z = %f | %f/n", radius_i, double(dist) ); } //std::cout << "circularity " << circularity << std::endl; } cmd_command(); //cv::Rect rect(320-40, 240-30, 80, 60); //cv::rectangle(cv_ptr->image, rect, cv::Scalar(0,0,255), 5); cv::imshow("origin", cv_ptr->image); cv::imshow("threshold", threshold_frame); cv::waitKey(3); ros::Time now = ros::Time::now(); //std::cout << "processing time : " << now - start << " sec" << std::endl; image_pub_.publish(cv_ptr->toImageMsg()); }
开发者ID:Hudhaifa,项目名称:opencv_test,代码行数:88,
示例4: CV_INSTRUMENT_REGIONbool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size region_size){ CV_INSTRUMENT_REGION() Mat img = _img.getMat(), cornersM = _corners.getMat(); int ncorners = cornersM.checkVector(2, CV_32F); CV_Assert( ncorners >= 0 ); Point2f* corners = cornersM.ptr<Point2f>(); const int nbins = 256; float ranges[] = {0, 256}; const float* _ranges = ranges; Mat hist; Mat black_comp, white_comp; for(int i = 0; i < ncorners; i++) { int channels = 0; Rect roi(cvRound(corners[i].x - region_size.width), cvRound(corners[i].y - region_size.height), region_size.width*2 + 1, region_size.height*2 + 1); Mat img_roi = img(roi); calcHist(&img_roi, 1, &channels, Mat(), hist, 1, &nbins, &_ranges); int black_thresh = 0, white_thresh = 0; segment_hist_max(hist, black_thresh, white_thresh); threshold(img, black_comp, black_thresh, 255.0, THRESH_BINARY_INV); threshold(img, white_comp, white_thresh, 255.0, THRESH_BINARY); const int erode_count = 1; erode(black_comp, black_comp, Mat(), Point(-1, -1), erode_count); erode(white_comp, white_comp, Mat(), Point(-1, -1), erode_count); std::vector<std::vector<Point> > white_contours, black_contours; std::vector<Vec4i> white_hierarchy, black_hierarchy; findContours(black_comp, black_contours, black_hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE); findContours(white_comp, white_contours, white_hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE); if(black_contours.size() < 5 || white_contours.size() < 5) continue; // find two white and black blobs that are close to the input point std::vector<std::pair<int, float> > white_order, black_order; orderContours(black_contours, corners[i], black_order); orderContours(white_contours, corners[i], white_order); const float max_dist = 10.0f; if(black_order[0].second > max_dist || black_order[1].second > max_dist || white_order[0].second > max_dist || white_order[1].second > max_dist) { continue; // there will be no improvement in this corner position } const std::vector<Point>* quads[4] = {&black_contours[black_order[0].first], &black_contours[black_order[1].first], &white_contours[white_order[0].first], &white_contours[white_order[1].first]}; std::vector<Point2f> quads_approx[4]; Point2f quad_corners[4]; for(int k = 0; k < 4; k++) { std::vector<Point2f> temp; for(size_t j = 0; j < quads[k]->size(); j++) temp.push_back((*quads[k])[j]); approxPolyDP(Mat(temp), quads_approx[k], 0.5, true); findCorner(quads_approx[k], corners[i], quad_corners[k]); quad_corners[k] += Point2f(0.5f, 0.5f); } // cross two lines Point2f origin1 = quad_corners[0]; Point2f dir1 = quad_corners[1] - quad_corners[0]; Point2f origin2 = quad_corners[2]; Point2f dir2 = quad_corners[3] - quad_corners[2]; double angle = acos(dir1.dot(dir2)/(norm(dir1)*norm(dir2))); if(cvIsNaN(angle) || cvIsInf(angle) || angle < 0.5 || angle > CV_PI - 0.5) continue; findLinesCrossPoint(origin1, dir1, origin2, dir2, corners[i]); } return true;}
开发者ID:cyberCBM,项目名称:DetectO,代码行数:78,
示例5: l0Smooth void l0Smooth(InputArray src, OutputArray dst, double lambda, double kappa) { Mat S = src.getMat(); CV_Assert(!S.empty()); CV_Assert(S.depth() == CV_8U || S.depth() == CV_16U || S.depth() == CV_32F || S.depth() == CV_64F); dst.create(src.size(), src.type()); if(S.data == dst.getMat().data) { S = S.clone(); } if(S.depth() == CV_8U) { S.convertTo(S, CV_32F, 1/255.0f); } else if(S.depth() == CV_16U) { S.convertTo(S, CV_32F, 1/65535.0f); } else if(S.depth() == CV_64F) { S.convertTo(S, CV_32F); } const double betaMax = 100000; // gradient operators in frequency domain Mat otfFx, otfFy; float kernel[2] = {-1, 1}; float kernel_inv[2] = {1,-1}; psf2otf(Mat(1,2,CV_32FC1, kernel_inv), otfFx, S.rows, S.cols); psf2otf(Mat(2,1,CV_32FC1, kernel_inv), otfFy, S.rows, S.cols); vector<Mat> denomConst; Mat tmp = pow2absComplex(otfFx) + pow2absComplex(otfFy); for(int i = 0; i < S.channels(); i++) { denomConst.push_back(tmp); } // input image in frequency domain vector<Mat> numerConst; dftMultiChannel(S, numerConst); /********************************* * solver *********************************/ double beta = 2 * lambda; while(beta < betaMax){ // h, v subproblem Mat h, v; filter2D(S, h, -1, Mat(1, 2, CV_32FC1, kernel), Point(0, 0), 0, BORDER_REPLICATE); filter2D(S, v, -1, Mat(2, 1, CV_32FC1, kernel), Point(0, 0), 0, BORDER_REPLICATE); Mat hvMag = h.mul(h) + v.mul(v); Mat mask; if(S.channels() == 1) { threshold(hvMag, mask, lambda/beta, 1, THRESH_BINARY); } else if(S.channels() > 1) { vector<Mat> channels(S.channels()); split(hvMag, channels); hvMag = channels[0]; for(int i = 1; i < S.channels(); i++) { hvMag = hvMag + channels[i]; } threshold(hvMag, mask, lambda/beta, 1, THRESH_BINARY); Mat in[] = {mask, mask, mask}; merge(in, 3, mask); } h = h.mul(mask); v = v.mul(mask); // S subproblem vector<Mat> denom(S.channels()); for(int i = 0; i < S.channels(); i++) { denom[i] = beta * denomConst[i] + 1; } Mat hGrad, vGrad; filter2D(h, hGrad, -1, Mat(1, 2, CV_32FC1, kernel_inv)); filter2D(v, vGrad, -1, Mat(2, 1, CV_32FC1, kernel_inv)); vector<Mat> hvGradFreq;//.........这里部分代码省略.........
开发者ID:AmbroiseMoreau,项目名称:opencv_contrib,代码行数:101,
示例6: cvtColorvoid AndarPelaParedeAteLinha::execute(Robotino *robotino){ float Vx = 200, Vy, w, distParede; float erroDist = 0; int paredeAlvo = robotino->paredeAlvo(); static State<Robotino> * voltar; static float a = std::sin(60*PI/180)/std::sin(80*PI/180); static float cos20 = std::cos(20*PI/180); static float K = R*(a-1); static float erro_int = 0; float e1 = robotino->irDistance(Robotino::IR_ESQUERDO_1); float e2 = robotino->irDistance(Robotino::IR_ESQUERDO_2); float ref_e1 = e2*a+K; float d1 = robotino->irDistance(Robotino::IR_DIREITO_1); float d2 = robotino->irDistance(Robotino::IR_DIREITO_2); float ref_d1 = 1.15*(d2*a+K); float distancia_da_esquerda, distancia_da_direita; float erro; vector<Vec4i> lines; Vec4i l, l2; Mat img, cdst; int num_linha = 0; int min_Hough = 70, dist_Hough = 50; int min_canny =150 , max_canny = 3*min_canny; distParede = robotino->getRefDistParede(); distParede += R; img = robotino->getImage(); cvtColor( img, cdst, CV_BGR2GRAY ); Canny( cdst, cdst, (double)min_canny, (double)max_canny, 3 ); convertScaleAbs(cdst, cdst); //cv::imshow("Canny",cdst); //cv::waitKey(1); threshold(cdst, cdst, (double)5, (double)255, CV_THRESH_BINARY); HoughLinesP(cdst, lines, 1, CV_PI/180, min_Hough, min_Hough, dist_Hough ); cvtColor( cdst, cdst, CV_GRAY2BGR ); if (paredeAlvo == Robotino::NORTEN90 || paredeAlvo == Robotino::OESTE0 || paredeAlvo == Robotino::SUL90 || paredeAlvo == Robotino::LESTE180){ erro = (e1-ref_e1); erro_int += erro*dt; w = Kp*erro+Ki*erro_int; distancia_da_esquerda = ((e1+ref_e1+2*R)*cos20)/2; erroDist = (distancia_da_esquerda) - distParede; Vy = Kpy*erroDist; std::cout << "erro dist: " << erroDist << "/n"; std::cout<< "Esquerda 1: " << e1 << std::endl; std::cout<< "RefEsquerda 1: " << ref_e1 << std::endl; std::cout<< "Esquerda 2: " << e2 << std::endl; std::cout << "Dist C++ throwIOException函数代码示例 C++ three函数代码示例
|