【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文本

 

posted on 2020-10-19 22:26  鹅要长大  阅读(972)  评论(0编辑  收藏  举报

导航