Esempio n. 1
0
void			deplace_term(int sigwinch)
{
	if (ig_good_size(get_size_x(), get_size_y(), get_long_work(CS), CS->size))
	{
		tputs(tgoto(tgetstr("cm", NULL), 0, 0), FD, tputs_putchar);
		tputs(tgetstr("cd", NULL), FD, tputs_putchar);
		print_length(CS, get_size_y());
		print_cursor(KEYUP);
		print_cursor(KEYDOWN);
	}
	else
		small_size();
	(void)sigwinch;
}
Esempio n. 2
0
bool CartoonEngine::Bilateral2(int iter_num,
                               int d,
                               double sigma_color,
                               double sigma_space) {
  if ((image_.empty()) || (CV_8UC3 != image_.type()) || (iter_num < 1))
    return false;
  
  // Step 1: convert color, only do filtering on the luminance channel.
  cv::Mat bgr_img = image_;
  cv::Mat lab_img;
  cv::cvtColor(bgr_img, lab_img, CV_BGR2Lab);
  std::vector<cv::Mat> lab_channels;
  cv::split(lab_img, lab_channels);
  cv::Mat temp;
  // Step 1: resize the original image to save pprocessing time (if needed).
  cv::Size2i small_size(cols_, rows_);
  if ((rows_ > 500) || (cols_ > 500)) {
    if (rows_ > cols_) {
      small_size.height = 500;
      small_size.width =
      static_cast<int>(500 * (static_cast<float>(cols_) / rows_));
    } else {
      small_size.width = 500;
      small_size.height =
      static_cast<int>(500 * (static_cast<float>(rows_) / cols_));
    }
    cv::resize(lab_channels[0], lab_channels[0], small_size);
    temp.create(small_size, CV_8UC1);
  } else {
    temp.create(rows_, cols_, CV_8UC1);
  }
  // Step 2: do bilateral filtering for several times for cartoon rendition.
  for (int i = 0; i < iter_num; ++i) {
    cv::bilateralFilter(lab_channels[0], temp, d, sigma_color, sigma_space);
    cv::bilateralFilter(temp, lab_channels[0], d, sigma_color, sigma_space);
  }
  // Step 3: luminance quantization.
  if(!LuminanceQuantization(&lab_channels[0], 8))
    return false;
  // Step 4: revert the original image size.
  if (small_size.width != cols_) {
    cv::resize(lab_channels[0], lab_channels[0], cv::Size2i(cols_, rows_));
  }
  cv::merge(lab_channels, lab_img);
  cv::cvtColor(lab_img, bgr_img, CV_Lab2BGR);
  bgr_img.copyTo(cartoon_);
  return true;
}
Esempio n. 3
0
bool CartoonEngine::Bilateral(int iter_num,
                              int d,
                              double sigma_color,
                              double sigma_space) {
  if ((image_.empty()) || (CV_8UC3 != image_.type()) || (iter_num < 1))
    return false;
  cv::Mat cartoon_img = image_;
  cv::Mat temp;
  // Step 1: resize the original image to save pprocessing time (if needed).
  cv::Size2i small_size(cols_, rows_);
  if ((rows_ > 500) || (cols_ > 500)) {
    if (rows_ > cols_) {
      small_size.height = 500;
      small_size.width =
      static_cast<int>(500 * (static_cast<float>(cols_) / rows_));
    } else {
      small_size.width = 500;
      small_size.height =
      static_cast<int>(500 * (static_cast<float>(rows_) / cols_));
    }
    cv::resize(cartoon_img, cartoon_img, small_size);
    temp.create(small_size, CV_8UC3);
  } else {
    temp.create(rows_, cols_, CV_8UC3);
  }
  // Step 2: do bilateral filtering for several times for cartoon rendition.
  for (int i = 0; i < iter_num; ++i) {
    cv::bilateralFilter(cartoon_img, temp, d, sigma_color, sigma_space);
    cv::bilateralFilter(temp, cartoon_img, d, sigma_color, sigma_space);
  }
  // Step 3: luminance quantization.
  // Step 4: revert the original image size.
  if (small_size.width != cols_) {
    cv::resize(cartoon_img, cartoon_img, cv::Size2i(cols_, rows_));
  }
  cartoon_img.copyTo(cartoon_);
  return true;
}
void skeletonize(const cv::Mat &input, cv::Mat &output, bool save_images)
{
    TS(total);

    TS(imwrite_0);
    if (save_images) cv::imwrite("0-input.png", input);
    TE(imwrite_0);

    // Convert to grayscale my
    cv::Mat gray_image_my;
    ConvertColor_BGR2GRAY_BT709_fpt(input, gray_image_my);
    if (save_images) cv::imwrite("1-convertcolor_my.png", gray_image_my);
    // Convert to grayscale my
    cv::Mat gray_image;
    ConvertColor_BGR2GRAY_BT709(input, gray_image);
    if (save_images) cv::imwrite("1-convertcolor.png", gray_image);

    // Downscale input image
    cv::Mat small_image;
    cv::Size small_size(input.cols / 1.5, input.rows / 1.5);
    ImageResize(gray_image, small_image, small_size);
    if (save_images) cv::imwrite("2-resize.png", small_image);

    // Binarization and inversion
    cv::threshold(small_image, small_image, 128, 255, cv::THRESH_BINARY_INV);
    if (save_images) cv::imwrite("3-threshold.png", small_image);

    // Thinning
    cv::Mat thinned_image;
    GuoHallThinning(small_image, thinned_image);
    if (save_images) cv::imwrite("4-thinning.png", thinned_image);

    // Back inversion
    output = 255 - thinned_image;
    if (save_images) cv::imwrite("5-output.png", output);

    TE(total);
}
Esempio n. 5
0
bool CartoonEngine::Convert2Painting(int neighbor, int levels) {
  if ((image_.empty()) || (CV_8UC3 != image_.type()))
    return false;
  
  // Resize image for fast processing.
  cv::Size2i small_size(cols_, rows_);
  cv::Mat img = image_;
  if ((rows_ > 300) || (cols_ > 300)) {
    if (rows_ > cols_) {
      small_size.height = 300;
      small_size.width =
      static_cast<int>(300 * (static_cast<float>(cols_) / rows_));
    } else {
      small_size.width = 300;
      small_size.height =
      static_cast<int>(300 * (static_cast<float>(rows_) / cols_));
    }
    cv::resize(img, img, small_size);
  }
  painting_.create(small_size.height, small_size.width, CV_8UC3);
  vector<int> hist(levels, 0);
  vector<int> b_sum(levels, 0);
  vector<int> g_sum(levels, 0);
  vector<int> r_sum(levels, 0);
  
  for (int r = 0; r < small_size.height; ++r) {
    for (int c = 0; c < small_size.width; ++c) {
      for (int i = 0; i < levels; ++i) {
        hist[i] = 0;
        b_sum[i] = g_sum[i] = r_sum[i] = 0;
      }
      int r_start = std::max(0, r - neighbor);
      int r_end = std::min(small_size.height, r + neighbor);
      int c_start = std::max(0, c - neighbor);
      int c_end = std::min(small_size.width, c + neighbor);
      for (int rr = r_start; rr < r_end; ++rr) {
        for (int cc = c_start; cc < c_end; ++cc) {
          cv::Vec3b pixel = img.at<cv::Vec3b>(rr, cc);
          int ind = static_cast<int>((pixel[0] + pixel[1] + pixel[2]) / 3) * (levels - 1) / 255;
          ++hist[ind];
          b_sum[ind] += static_cast<int>(pixel[0]);
          g_sum[ind] += static_cast<int>(pixel[1]);
          r_sum[ind] += static_cast<int>(pixel[2]);
        }
      }
      
      int new_ind = 0;
      int cur_max = hist[0];
      for (int l = 1; l < levels; ++l) {
        if (hist[l] > hist[new_ind]) {
          new_ind = l;
          cur_max = hist[l];
        }
      }
      
      painting_.at<cv::Vec3b>(r, c)[0] =
      static_cast<uchar>(b_sum[new_ind] / cur_max);
      painting_.at<cv::Vec3b>(r, c)[1] =
      static_cast<uchar>(g_sum[new_ind] / cur_max);
      painting_.at<cv::Vec3b>(r, c)[2] =
      static_cast<uchar>(r_sum[new_ind] / cur_max);
    }
  }
  if (small_size.width != cols_) {
    cv::resize(painting_, painting_, cv::Size2i(cols_, rows_));
  }
  return true;
}
void ClothingSearcher::getTheMaskOfCloth(const Mat &image, Mat &mask,
                                    const std::vector<int> floodfill_thresholds )
{
    if( image.channels() == 1 )
        return;
    //get the mask of cloth region using floodfill algorithm
    Mat edges;
    computeEdgeMap( image, edges );


    //to lower down the complexity, resize the original image to smaller one
    Mat small_image;
    Size small_size( image.cols, image.rows );
    if( image.cols > 320 ){
        float scale = image.cols / 320;
        small_size.width = image.cols / scale;
        small_size.height = image.rows / scale;
        cv::resize( image, small_image, small_size );
    }
    else
        small_image = image.clone();


    //convert to yuv color space
    Mat yuv = Mat( small_size, CV_8UC3 );
    cvtColor( small_image, yuv, CV_BGR2RGB );

    //the mask used in floodfill should be 2 pixels widther and higher than the image
    int sw = small_size.width;
    int sh = small_size.height;
    Mat mask_plus_border;
    mask_plus_border = Mat::zeros( sh + 2, sw + 2, CV_8UC1 );
    mask = mask_plus_border( cv::Rect( 1, 1, sw, sh ) );
    cv::resize( edges, mask, small_size );

    closeOperation( mask );

    cv::Rect rect;
    prepareSeedsRegionForFloodfill( small_image, rect );

    rectangle( small_image, rect, Scalar( 0, 255, 0 ) );

    //imshow( "tets", small_image );
    waitKey(0);


    Scalar lowerDiff = Scalar( floodfill_thresholds[0], floodfill_thresholds[0], floodfill_thresholds[0] );
    Scalar upperDiff = Scalar( floodfill_thresholds[0], floodfill_thresholds[0], floodfill_thresholds[0]);
    const int CONNECTED_COMPONENTS = 4;
    const int flags = CONNECTED_COMPONENTS |  FLOODFILL_FIXED_RANGE | FLOODFILL_MASK_ONLY;
    Mat edge_mask = mask.clone();

    const int X_POINTS = 8;
    const int Y_POINTS = 8;
    const int X_STEP = rect.width / X_POINTS;
    const int Y_STEP = rect.height / Y_POINTS;
    for( int i = rect.x + X_STEP; i < (int)(rect.x + rect.width ); i += X_STEP ){
        for( int j = rect.y + Y_STEP; j < (int)(rect.y + rect.height ); j += Y_STEP ){
            circle( small_image, cv::Point( i, j), 3, Scalar( 0, 0, 255 ) );
            floodFill( yuv, mask_plus_border, cv::Point( i, j), Scalar(), NULL,
                       lowerDiff, upperDiff, flags );
        }
    }

    //imshow( "mask", small_image );
    waitKey(0);
    mask -= edge_mask;

}