본문 바로가기
TensorFlow OpenCV

Windows GDI와 OPENCV 혼용, PolyBezier + Mat 2018. 1. 16.

by BABEL-II 2019. 10. 5.
 

void polybezier()

{

Mat image(400, 400, CV_8UC3);

image.setTo(Scalar(255, 255, 255));

imshow("BezierPoly", image);

 

Mat imdeer = imread("C:\\temp\\siksin\\173646402820_middle.jpg");

imshow("Deer", imdeer);

Mat result(400, 400, CV_8UC3);

result.setTo(Scalar(255, 255, 255));

 

while (1) {

  int k = waitKey(1);

  if (k == 27)

   break;

  if (k == 'd'){

   HWND hwnd = FindWindow(NULL, L"BezierPoly");

   HDC hdc = GetDC(hwnd);

   POINT point[4];

   point[0].x = 100; point[1].x = 150; point[2].x = 200; point[3].x = 100;

   point[0].y = 100; point[1].y = 150; point[2].y = 50; point[3].y = 100;

   PolyBezier(hdc, point, 4);

   HANDLE oldobj = SelectObject(hdc, GetStockObject(BLACK_BRUSH));

   ExtFloodFill(hdc,

    (point[0].x + point[1].x + point[2].x + point[3].x) / 4,

    (point[0].y + point[1].y + point[2].y + point[3].y) / 4,

    RGB(0, 0, 0), FLOODFILLBORDER);

   SelectObject(hdc, oldobj);

 

   for (int r = 0; r < 400; r++) {

    for (int c = 0; c < 400; c ++ ) {

     COLORREF color = GetPixel(hdc, c, r);

     if (color == RGB(0, 0, 0)) {

      Point p = { r, c };

      result.at<Vec3b>(r, c)[0] = imdeer.at<Vec3b>(r, c)[0];

      result.at<Vec3b>(r, c)[1] = imdeer.at<Vec3b>(r, c)[1];

      result.at<Vec3b>(r, c)[2] = imdeer.at<Vec3b>(r, c)[2];

     }

    }

   }

   ReleaseDC(hwnd, hdc);

 

   imshow("result", result);

   imwrite("c:\\temp\\siksin\\bezierpoly-result.jpg", result);

  }

}

}