当前位置: 首页>>代码示例>>C++>>正文


C++ OpticalFlow::setLambdaTwo方法代码示例

本文整理汇总了C++中OpticalFlow::setLambdaTwo方法的典型用法代码示例。如果您正苦于以下问题:C++ OpticalFlow::setLambdaTwo方法的具体用法?C++ OpticalFlow::setLambdaTwo怎么用?C++ OpticalFlow::setLambdaTwo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpticalFlow的用法示例。


在下文中一共展示了OpticalFlow::setLambdaTwo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: displayImage


//.........这里部分代码省略.........
  cvMoveWindow(controlWindowName, frameSize.width + 30, infoImageSize.height + 60);


  cv::Mat displayImage(frameSize, CV_8UC3);//IPL_DEPTH_8U, 3);
  cv::Mat infoImage(infoImageSize, CV_8UC3);//, IPL_DEPTH_8U, 3);

  int lineMulFactor = 1, ellipseMulFactor = 0, gridSpacing = 10; // Optical flow drawing parameters
  int lambdaZero_x_1000  = int(1000.0 * lambdaZero);
  int lambdaOne_x_1000   = int(1000.0 * lambdaOne);
  int lambdaTwo_x_1000   = int(1000.0 * lambdaTwo);
  int lambdaPrior_x_1000 = int(1000.0 * lambdaPrior); 


  cvCreateTrackbar("line mul factor", controlWindowName, &lineMulFactor, 10000, NULL);
  cvCreateTrackbar("ellipse mul factor", controlWindowName, &ellipseMulFactor, 80, NULL);
  cvCreateTrackbar("grid spacing", controlWindowName, &gridSpacing, 100, NULL);
  cvCreateTrackbar("lambdaZero x 1000", controlWindowName, &lambdaZero_x_1000, 2000, NULL);
  cvCreateTrackbar("lambdaOne x 1000", controlWindowName, &lambdaOne_x_1000, 2000, NULL);
  cvCreateTrackbar("lambdaTwo x 1000", controlWindowName, &lambdaTwo_x_1000, 2000, NULL);
  cvCreateTrackbar("lambdaPrior x 1000", controlWindowName, &lambdaPrior_x_1000, 2000, NULL);
  cvCreateTrackbar("n levels", controlWindowName, &nLevels, maxLevels, NULL);

  std::cout << "Press ESC to exit." << std::endl;

  while((pressedKey = cvWaitKey(10)) != 'q') { //CB_ESC) {

    gridSpacing = MAX(gridSpacing, 1);
    nLevels = MAX(nLevels, 1);

    lambdaZero  = float(lambdaZero_x_1000)  / 1000.0;
    lambdaOne   = float(lambdaOne_x_1000)   / 1000.0;
    lambdaTwo   = float(lambdaTwo_x_1000)   / 1000.0;
    lambdaPrior = float(lambdaPrior_x_1000) / 1000.0;

    optFlow.setLambdaZero(lambdaZero);
    optFlow.setLambdaOne(lambdaOne);
    optFlow.setLambdaTwo(lambdaTwo);
    optFlow.setLambdaPrior(lambdaPrior);
    
    capture >> frame;
    if(frame.empty()) break;
    cv::cvtColor(frame, auxBW, CV_BGR2GRAY);  
    auxBW.convertTo(frames[nextIdx], CV_32FC1, 1/255.0);

        
    /* *
     * Compute optical flow
     * */
    if(optFlow.getNLevels() != nLevels) {
      optFlow.init(frames[prevIdx], frames[currIdx],
		   nLevels, windowSide,
		   lambdaZero, lambdaOne, lambdaTwo, lambdaPrior);    
    }
    
    CUT_SAFE_CALL( cutResetTimer(timer) );
    CUT_SAFE_CALL( cutStartTimer(timer) );
    
    optFlow(frames[nextIdx], mu_x, mu_y, Lambda_xx, Lambda_yy, Lambda_xy);

    CUDA_SAFE_CALL( cudaThreadSynchronize() );
    CUT_SAFE_CALL( cutStopTimer(timer) );
    gpuTime = cutGetTimerValue(timer);
    gpuAccumTime = gpuTime + 0.9 * gpuAccumTime;
    totalWeight  = 1.0 + 0.9 * totalWeight;
    fps = totalWeight / (gpuAccumTime / 1000.0) /*gpuAccumTime is in ms*/; 

    fps = 1000 / gpuTime;

    /* *
     * Display results
     * */
    frame.convertTo(displayImage, CV_8UC3);
    drawBayesianOpticalFlow(displayImage, 
			    mu_x, mu_y,
			    Lambda_xx, Lambda_yy, Lambda_xy,
			    cvSize(gridSpacing, gridSpacing),
			    lineMulFactor, ellipseMulFactor);
    
    int lineNo = 0;    
    infoImage.setTo(cv::Scalar(0,0,0));
    drawText(infoImage, textCorner, lineNo++, "Press ESC to exit");
    lineNo++;
    drawLabelValuePair(infoImage, textCorner, lineNo++, "lambda zero", lambdaZero);
    drawLabelValuePair(infoImage, textCorner, lineNo++, "lambda one", lambdaOne);
    drawLabelValuePair(infoImage, textCorner, lineNo++, "lambda two", lambdaTwo);
    drawLabelValuePair(infoImage, textCorner, lineNo++, "lambda prior", lambdaPrior);
    drawLabelValuePair(infoImage, textCorner, lineNo++, "FPS", fps); 
    drawLabelValuePair(infoImage, textCorner, lineNo++, "n Levels", nLevels); 

    cv::imshow(displayWindowName, displayImage);
    cv::imshow(controlWindowName, infoImage);


    prevIdx = currIdx;
    currIdx = nextIdx;
    nextIdx = (nextIdx + 1)%3;
  }
  
  return EXIT_SUCCESS;
}
开发者ID:Anantak,项目名称:CUDABOF,代码行数:101,代码来源:test04_opticalFlow.cpp


注:本文中的OpticalFlow::setLambdaTwo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。