C# EmguCV蛇函数
我正在尝试使用EmguCV中的snake活动轮廓,但我什么都不做。以下是我的代码:C# EmguCV蛇函数,c#,emgucv,C#,Emgucv,我正在尝试使用EmguCV中的snake活动轮廓,但我什么都不做。以下是我的代码: Image<Gray, Byte> img = new Image<Gray, Byte>(300, 300, new Gray()); Point center = new Point(100, 100); double width = 20; double height = 40; Rectangle rect = new Recta
Image<Gray, Byte> img = new Image<Gray, Byte>(300, 300, new Gray());
Point center = new Point(100, 100);
double width = 20;
double height = 40;
Rectangle rect = new Rectangle(center, new Size(20, 20));
img.Draw(rect, new Gray(255.0), -1);
using (MemStorage stor = new MemStorage())
{
Seq<Point> pts = new Seq<Point>((int)SEQ_TYPE.CV_SEQ_POLYGON, stor);
pts.Push(new Point(20, 20));
pts.Push(new Point(20, 280));
pts.Push(new Point(280, 280));
pts.Push(new Point(280, 20));
//Image<Gray, Byte> canny = img.Canny(100.0, 40.0);
Seq<Point> snake = img.Snake(pts, 0.1f, 0.5f, 0.4f, new Size(21, 21), new MCvTermCriteria(500, 0.1), stor);
img.Draw(pts, new Gray(120), 1);
img.Draw(snake, new Gray(80), 2);
Image img=新图像(300300,新灰度());
点中心=新点(100100);
双倍宽度=20;
双倍高度=40;
矩形rect=新矩形(中心,新尺寸(20,20));
图像绘制(矩形,新灰色(255.0),-1);
使用(MemStorage story=new MemStorage())
{
Seq pts=新的Seq((int)Seq_TYPE.CV_Seq_POLYGON,stor);
点推(新点(20,20));
点推(新点(20280));
点推(新点(280280));
点推(新点(280,20));
//图像canny=img.canny(100.0,40.0);
Seq snake=img.snake(pts,0.1f,0.5f,0.4f,新尺寸(21,21),新MCVTERM标准(500,0.1),stor);
图像绘制(pts,新灰色(120),1);
图像绘制(蛇,新灰色(80),2);
我做错了什么?知道吗?您没有画出初始化点 我已经为你和整个社区设置了一些代码,因为那里没有emgu蛇样本
private void TestSnake()
{
Image<Gray, Byte> grayImg = new Image<Gray, Byte>(400, 400, new Gray());
Image<Bgr, Byte> img = new Image<Bgr, Byte>(400, 400, new Bgr(255,255,255));
// draw an outer circle on gray image
grayImg.Draw(new Ellipse(new PointF(200,200),new SizeF(100,100),0), new Gray(255.0), -1);
// inner circle on gray image to create a donut shape :-)
grayImg.Draw(new Ellipse(new PointF(200, 200), new SizeF(50, 50), 0), new Gray(0), -1);
// this is the center point we'll use to initialize our contour points
Point center = new Point(200, 200);
// radius of polar points
double radius = 70;
using (MemStorage stor = new MemStorage())
{
Seq<Point> pts = new Seq<Point>((int)Emgu.CV.CvEnum.SEQ_TYPE.CV_SEQ_POLYGON, stor);
int numPoint = 100;
for (int i = 0; i < numPoint; i++)
{ // let's have some fun with polar coordinates
Point pt = new Point((int)(center.X + (radius * Math.Cos(2 * Math.PI * i / numPoint))), (int)(center.Y + (radius * Math.Sin(2 * Math.PI * i / numPoint))) );
pts.Push(pt);
}
// draw contour points on result image
img.Draw(pts, new Bgr(Color.Green), 2);
// compute snakes
Seq<Point> snake = grayImg.Snake(pts, 1.0f, 1.0f, 1.0f, new Size(21, 21), new MCvTermCriteria(100, 0.0002), stor);
// draw snake result
img.Draw(snake, new Bgr(Color.Yellow), 2);
// use for display in a winform sample
imageBox1.Image = grayImg;
imageBox2.Image = img;
}
}
private void TestSnake()
{
图像灰度img=新图像(400400,新灰度());
图像img=新图像(400400,新Bgr(255255));
//在灰色图像上画一个外圆
灰度图(新椭圆(新点F(200200),新尺寸F(100100),0),新灰度(255.0),-1);
//用于创建圆环形状的灰色图像上的内圈:-)
灰度图(新椭圆(新点F(200,200),新尺寸F(50,50),0),新灰度(0),-1);
//这是我们用来初始化轮廓点的中心点
点中心=新点(200200);
//极点半径
双半径=70;
使用(MemStorage story=new MemStorage())
{
Seq pts=新的Seq((int)Emgu.CV.CvEnum.Seq_TYPE.CV_Seq_POLYGON,stor);
int numPoint=100;
对于(int i=0;i
希望这有帮助,只需更改一些参数,您就会对结果感到惊讶
无法绘制初始化点 我已经为你和整个社区设置了一些代码,因为那里没有emgu蛇样本
private void TestSnake()
{
Image<Gray, Byte> grayImg = new Image<Gray, Byte>(400, 400, new Gray());
Image<Bgr, Byte> img = new Image<Bgr, Byte>(400, 400, new Bgr(255,255,255));
// draw an outer circle on gray image
grayImg.Draw(new Ellipse(new PointF(200,200),new SizeF(100,100),0), new Gray(255.0), -1);
// inner circle on gray image to create a donut shape :-)
grayImg.Draw(new Ellipse(new PointF(200, 200), new SizeF(50, 50), 0), new Gray(0), -1);
// this is the center point we'll use to initialize our contour points
Point center = new Point(200, 200);
// radius of polar points
double radius = 70;
using (MemStorage stor = new MemStorage())
{
Seq<Point> pts = new Seq<Point>((int)Emgu.CV.CvEnum.SEQ_TYPE.CV_SEQ_POLYGON, stor);
int numPoint = 100;
for (int i = 0; i < numPoint; i++)
{ // let's have some fun with polar coordinates
Point pt = new Point((int)(center.X + (radius * Math.Cos(2 * Math.PI * i / numPoint))), (int)(center.Y + (radius * Math.Sin(2 * Math.PI * i / numPoint))) );
pts.Push(pt);
}
// draw contour points on result image
img.Draw(pts, new Bgr(Color.Green), 2);
// compute snakes
Seq<Point> snake = grayImg.Snake(pts, 1.0f, 1.0f, 1.0f, new Size(21, 21), new MCvTermCriteria(100, 0.0002), stor);
// draw snake result
img.Draw(snake, new Bgr(Color.Yellow), 2);
// use for display in a winform sample
imageBox1.Image = grayImg;
imageBox2.Image = img;
}
}
private void TestSnake()
{
图像灰度img=新图像(400400,新灰度());
图像img=新图像(400400,新Bgr(255255));
//在灰色图像上画一个外圆
灰度图(新椭圆(新点F(200200),新尺寸F(100100),0),新灰度(255.0),-1);
//用于创建圆环形状的灰色图像上的内圈:-)
灰度图(新椭圆(新点F(200,200),新尺寸F(50,50),0),新灰度(0),-1);
//这是我们用来初始化轮廓点的中心点
点中心=新点(200200);
//极点半径
双半径=70;
使用(MemStorage story=new MemStorage())
{
Seq pts=新的Seq((int)Emgu.CV.CvEnum.Seq_TYPE.CV_Seq_POLYGON,stor);
int numPoint=100;
对于(int i=0;i
希望这有帮助,只需更改一些参数,您就会对结果感到惊讶