2016-04-02 9 views
0

C++のopencvコードdemo drawContour functionalityをC#に変換しようとしています。関数API Cv2.ApproxPolyDPの関数引数contours0 [k]と等高線[k]に問題があります。私はCv2.ApproxPolyDP呼び出しのために無効なパラメータのいくつかを示すDesign Timeコンパイラエラーを取得します。問題のコードは以下のとおりです。あなたの助けを前にありがとう。 "approxPolyDP(MAT(contours0 [K])、輪郭[K]、3、TRUE);"C++コードをC#コードに変換する

using System; 
using System.Collections.Generic; 
using System.Windows.Forms; 
using OpenCvSharp; 

class Program 
{ 
    const int w = 500; 
    static int levels = 3; 
    static Point[][] contours; 
    static HierarchyIndex[] hierarchy; 

    static void on_trackbar(int pos, object UseData) 
    { 
     Mat cnt_img = Mat.Zeros(w, w, MatType.CV_8UC3); 
     int _levels = levels - 3; 
     Cv2.DrawContours(cnt_img, contours, _levels <= 0 ? 3 : -1, Scalar.White, 
      3, LineTypes.AntiAlias, hierarchy, Math.Abs(_levels)); 
     Cv2.ImShow("contours", cnt_img); 
    } 

    static void Main() 
    { 
     Mat img = Mat.Zeros(w, w, MatType.CV_8UC1); 

     //Draw 6 faces 
     for(int i = 0; i < 6; i++) 
     { 
      int dx = (i % 2) * 250 - 30; 
      int dy = (i/2)*150; 
      Scalar white = Scalar.White; 
      Scalar black = Scalar.Black; 

      if(i == 0) 
      { 
       for(int j = 0; j <= 10; j++) 
       { 
        double angle = (j + 5) * Math.PI/21; 
        Cv2.Line(img, 
         new Point(Math.Round(dx + 100 + j * 10 - 80 * Math.Cos(angle), 0), 
          Math.Round(dy + 100 - 90 * Math.Sin(angle), 0)), 
         new Point(Math.Round(dx + 100 + j * 10 - 30 * Math.Cos(angle), 0), 
          Math.Round(dy + 100 - 30 * Math.Sin(angle), 0)), 
          white, 1); 
       } 
      } 

      Cv2.Ellipse(img, new Point(dx + 150, dy + 100), new Size(100, 70), 0, 0, 360, white); 
      Cv2.Ellipse(img, new Point(dx + 115, dy + 70), new Size(30, 20), 0, 0, 360, black); 
      Cv2.Ellipse(img, new Point(dx + 185, dy + 70), new Size(30, 20), 0, 0, 360, black); 
      Cv2.Ellipse(img, new Point(dx + 115, dy + 70), new Size(15, 15), 0, 0, 360, white); 
      Cv2.Ellipse(img, new Point(dx + 185, dy + 70), new Size(15, 15), 0, 0, 360, white); 
      Cv2.Ellipse(img, new Point(dx + 115, dy + 70), new Size( 5, 5), 0, 0, 360, black); 
      Cv2.Ellipse(img, new Point(dx + 185, dy + 70), new Size( 5, 5), 0, 0, 360, black); 
      Cv2.Ellipse(img, new Point(dx + 150, dy + 100), new Size(10, 5), 0, 0, 360, black); 
      Cv2.Ellipse(img, new Point(dx + 150, dy + 150), new Size(40, 10), 0, 0, 360, black); 
      Cv2.Ellipse(img, new Point(dx + 27, dy + 100), new Size(20, 35), 0, 0, 360, white); 
      Cv2.Ellipse(img, new Point(dx + 273, dy + 100), new Size(20, 35), 0, 0, 360, white); 
     } 

     //show the faces 
     Cv2.ImShow("image", img); 

     //Extract the contours so that 
     Point[][] contours0; 
     Cv2.FindContours(img, out contours0, out hierarchy, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple); 
     contours = new Point[contours0.Length][]; 

     for(int k = 0; k < contours0.Length; k++) 
      Cv2.ApproxPolyDP(contours0[k], contours[k], 3, true); // compiler error! 

     CvTrackbar Track = new CvTrackbar("levels+3", "contours", 3, 7, on_trackbar); 
     on_trackbar(0, 0); 

     Cv2.WaitKey(); 
    } 
} 
+0

どのようなエラーが表示されますか?トラブルをもう少し説明してください。 –

+0

Cv2.FindContours(...)および/またはCv2.ApproxPolyDP(...)関数に無効なパラメータ型が渡されています。 –

答えて

0

IはC++ラインを書くために必要なC#ライン "contours [k] = Cv2.ApproxPolyDP(contours0 [k]、3、true);"

関連する問題