【opencv基礎】隨機顏色生成


code

  // show contour points.
  cv::Scalar color(rand()&255, rand()&255, rand()&255); 
  // cv::Mat showimg1 = cv::Mat::zeros(cv::Size(out_w_, out_h_), CV_8UC3);  
  // std::cout << "show contour points: " << contour_point.size() << std::endl;
  // drawContours(showimg1, contour_, -1, color, -1, 8, hierarchy);
  for(int i=0; i<contour_point.size(); i++)
  {
    cv::circle(showimg, contour_point[i], 2, color);
  }
  // // get ROI with line.
  // color = cv::Scalar(rand()&255, rand()&255, rand()&255); 
  // cv::rectangle(showimg, roi_, color, 1, cv::LINE_8, 0);
  // cv::line(showimg, cv::Point(0.5*out_w_, 0.5*out_h_),
  //   cv::Point(0.5*out_w_, out_h_), color, cv::LINE_8, 0);
  cv::imshow("contour_", showimg);
  cv::waitKey(1);
  sprintf(output_path_, "../output/%04d_contour_points.png", idx_);
  cv::imwrite(output_path_, showimg);
View Code

 

  

 

參考

1. OpenCV中隨機顏色

2. 創建圖片並隨機設置圖片顏色

3. 隨機生成器和OpenCV文本

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM