C++ opencv kodunu demo drawContour functionality C# ye dönüştürmeye çalışıyorum. Fonksiyon argümanları contours0 [k] ve konturları [k] API Cv2.ApproxPolyDP işlevinde sorun yaşıyorum. Cv2.ApproxPolyDP çağrısı için bazı parametrelerin geçersiz olduğunu belirten Tasarım zaman derleyicisi hatası alıyorum. Söz konusu kod aşağıda listelenmiştir. Yardımlarınız için şimdiden teşekkür ederiz. "ApproxPolyDP (Mal (contours0 [k]), konturlar [k], 3, doğru);"C++ kodunu C# koduna dönüştürme
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();
}
}
Hangi hatalarla karşılaşıyorsunuz? Sorunları biraz daha açıkla. –
Bir derleyici sözdizimi hatası belirten: geçersiz parametre türü Cv2.FindContours (...) ve/veya Cv2.ApproxPolyDP (...) işlevine iletiliyor. –