Пример #1
0
void Methods::signAlign(Mat dst)
{
	
	//find angle 
	//Image(Mat*image, int yu, int yl, int xl, int xr, Point2f temp);
	Mat temp1,temp2;
	temp1 = dst(Rect(0, 0, dst.cols / 2, dst.rows));
	temp2 = dst(Rect(dst.cols / 2, 0, dst.cols / 2, dst.rows));
	Image temp_image1(&temp1, 0, temp1.rows, 0, temp1.cols, Point2f(0, 0));
	Image temp_image2(&temp2, 0, temp2.rows, 0, temp2.cols, Point2f(0, 0));
	cout << "BEFORE\n";
	cout << temp_image1.x_left << "-Upper  down-" << temp_image1.y_lower<<"   ";
	cout << temp_image2.x_left << "-Upper  down-" << temp_image2.y_lower;
	CropImage(&temp_image1, 20);
	CropImage(&temp_image2, 20);
	cout << "\nAFTER\n";
	cout << temp_image1.x_left << "-Upper  down-" << temp_image1.y_lower << "   ";
	cout << temp_image2.x_left << "-Upper  down-" << temp_image2.y_lower << "\n\n";
	//float angle1=calculateAngle(Point2f(temp_image1.x_left, temp_image1.y_upper), Point2f(temp_image2.x_left, temp_image2.y_upper));
	float angle2 = calculateAngle(Point2f(0, temp_image1.y_lower), Point2f(1, temp_image2.y_lower));
	namedWindow("temp1", CV_WINDOW_NORMAL);
	namedWindow("temp2", CV_WINDOW_NORMAL);
	imshow("temp1", temp1);
	imshow("temp2", temp2);
	waitKey(0);
	cout << angle2<<"\n\n";
	double angle = angle2;
	rotateByAngle(dst, angle);

}
Пример #2
0
std::vector<Vector3f> Retexture::applyGaussianFilter(std::vector<Vector3f> inpainted, int width, int height, int frosty)
{

      std::vector<Vector3f> temp_image (width * height);
      std::fill(temp_image.begin(), temp_image.end(), Vector3f(0, 0, 0));
      double total_weight;
      double val;

      if (!frosty) {
          // Not doin it
          return inpainted;
      }

      // Create the kernel

      double sigma = m_frosty;
      double s = sigma * 3;
      double kernel[(int) ((s * 2) + 1)];


      double coefficient = 1 / (sigma * sqrt(2 * M_PI));
      double exponent;
      double x;
      double gaussian;
      for (int i = 0; i < (2 * sigma * 3) + 1; ++i)
      {
        x = fabs(s - i);
        exponent = (-1 * x * x) / (2 * sigma * sigma);
        gaussian = coefficient * pow(M_E, exponent);
        kernel[i] = gaussian;
      }


      // Changing bounds so don't have to deal with edges now
      for (int i = 0; i < width; i++) {
        for (int j = 0;  j < height; j++) {

          val = 0;
          total_weight = 0;

          int index1D = width*j + i;

          for (int dx = -s; dx <= s; dx++) {
              if (dx+i >= 0 && dx+i < width) {
                  int origIndex = width * j + (i + dx);
                  temp_image[index1D] += (inpainted[origIndex] * kernel[(int) (dx+s)]);
                  total_weight += kernel[(int) (dx+s)];
              }
          }

          temp_image[index1D] = temp_image[index1D] / total_weight;
          //std::cout << temp_image[index1D] << std::endl;

        }
      }

      std::vector<Vector3f> temp_image2 (width * height);
      std::fill(temp_image2.begin(), temp_image2.end(), Vector3f(0, 0, 0));

      // Changing bounds so don't have to deal with edges now
      for (int i = 0; i < width; i++) {
        for (int j = 0;  j < height; j++) {

          val = 0;
          total_weight = 0;
          int index1D = width*j + i;

          for (int dy = -s;  dy <= s; dy++) {
              if (dy+j >= 0 && dy+j < height) {
                  int origIndex = width*(j+dy) + i;
                  temp_image2[index1D] += (temp_image[origIndex] * kernel[(int) (dy+s)]);
                  total_weight += kernel[(int) (dy+s)];
              }
          }

          temp_image2[index1D] = (temp_image2[index1D] / total_weight);//Vector3f(Vector3f(0.7, 0.4, 0.4).array() * (temp_image2[index1D] / total_weight).array());
        }
      }


    return temp_image2;
}