Difference between revisions of "Edge"
From Ilianko
Line 33: | Line 33: | ||
=====Edge detection===== | =====Edge detection===== | ||
+ | |||
+ | <code><pre> | ||
namespace WindowsFormsApplication1 | namespace WindowsFormsApplication1 | ||
{ | { | ||
Line 123: | Line 125: | ||
} | } | ||
} | } | ||
+ | </pre></code> | ||
=====Objects detection===== | =====Objects detection===== |
Revision as of 06:56, 23 April 2015
Contents
Разпознаване на геометрични обекти
Намиране на ръбове(Edge Detection)
Матлаб
im = imread("lena.tif");
Sy = [-1 -2 -1; 0 0 0; 1 2 1];
Sx = Sy';
Gr = im(:,:,1)*0.2+im(:,:,2)*0.7+im(:,:,3)*0.1;
DimY = conv2(Sy,Gr);
DimX = conv2(Sx,Gr);
DimYn = DimY./max(max(DimY));
DimXn = DimX./max(max(DimX));
figure
imshow(DimYn);
figure
imshow(DimXn);
Dim = (DimY.^2 + DimX.^2).^(1/2);
Dimn = Dim./max(max(Dim));
figure
imshow(Dimn)
figure
imshow(Dimn > 0.2)
OpenCV
Размер на изображението (кадъра)
Edge detection
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DispatcherTimer timer = new DispatcherTimer();
private Capture cap = new Capture();
Image<Bgr, byte> frame;
private void Form1_Load(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(100, 100);
frame = cap.QueryFrame();
this.Size = frame.Size;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Bgr color = new Bgr(255, 0, 0);
frame = new Image<Bgr, byte>(this.Size.Width, this.Size.Height, color);
pictureBox1.Image = frame.Bitmap;
Thread workerThread = new Thread(showImage);
workerThread.Start();
}
private void button1_Click(object sender, EventArgs e)
{
}
void showImage()
{
MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 10.0, 10.0);
Bgr color = new Bgr(255, 255, 255);
Bgr Bcolor = new Bgr(255, 0, 0);
frame = new Image<Bgr, byte>(frame.Size.Width, frame.Size.Height, Bcolor);
frame.Draw("0", ref font, new Point(250, 250), color);
pictureBox1.Image = frame.Bitmap;
System.Threading.Thread.Sleep(1000);
frame = new Image<Bgr, byte>(frame.Size.Width, frame.Size.Height, Bcolor);
frame.Draw("1", ref font, new Point(250, 250), color);
pictureBox1.Image = frame.Bitmap;
System.Threading.Thread.Sleep(1000);
frame = new Image<Bgr, byte>(frame.Size.Width, frame.Size.Height, Bcolor);
frame.Draw("2", ref font, new Point(250, 250), color);
pictureBox1.Image = frame.Bitmap;
System.Threading.Thread.Sleep(1000);
frame = cap.QueryFrame();
pictureBox1.Image = frame.Bitmap;
System.Threading.Thread.Sleep(1000);
timer.Tick += new EventHandler(timer_tick);
timer.Interval = new TimeSpan(0, 0, 0, 0, 35);
timer.Start();
}
void timer_tick(object sender, EventArgs e)
{
frame = cap.QueryFrame();
Image<Gray, Byte> cannyEdges = frame.Convert<Gray, Byte>().Canny(100, 60);//cannyThreshold, cannyThresholdLinking);
pictureBox1.Image = cannyEdges.Bitmap;
}
}
}
Objects detection
Motion detection
Change background
webcam
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
refreshImage = function()
{
img = document.getElementById("cam");
img.src="xxx.jpg?"+Math.random();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Auto-Refresh</title>
</head>
<body onload="window.setInterval(refreshImage, 1*1000);">
<img src="xxx.jpg?xxx" id="cam" />
</body>
</html>
Image MySystemImage = frame.ToBitmap(); MySystemImage.Save("xxx.jpg", ImageFormat.Jpeg);
using System.IO; using System.Drawing.Imaging;