Last active
October 17, 2018 01:29
-
-
Save paulohenriquesn/2feebc5b08dd743aac0c53a6371b9baf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Emgu.CV; | |
using Emgu.CV.UI; | |
using Emgu.CV.Structure; | |
using System.Threading; | |
namespace WindowsFormsApp1 | |
{ | |
public class Connection | |
{ | |
public string IPStream { get; set; } | |
public bool Connected { get; set; } | |
public ImageViewer imageViewer { get; set; } | |
public VideoCapture videoCapture { get; set; } | |
public Bitmap bitmap { get; set; } | |
} | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
public Connection connection = new Connection(); | |
public string Read = String.Empty; | |
public Bitmap CropBitmap(Bitmap bitmap, int cropX, int cropY, int cropWidth, int cropHeight) | |
{ | |
Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight); | |
Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat); | |
return cropped; | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
this.CenterToScreen(); | |
} | |
private void timer1_Tick(object sender, EventArgs e) | |
{ | |
label1.Text = Read; | |
new Task(() => | |
{ | |
if (connection.Connected == true) | |
{ | |
try | |
{ | |
connection.imageViewer.Image = connection.videoCapture.QueryFrame(); | |
connection.bitmap = CropBitmap(connection.imageViewer.Image.Bitmap, 50, 50, 250, 130); | |
} | |
catch { } | |
WebCamUpdate(); | |
} | |
}).Start(); | |
} | |
private void WebCamUpdate() | |
{ | |
try | |
{ | |
TesseractEngine engine = new TesseractEngine("./tessdata", "eng", EngineMode.Default); | |
Page page = engine.Process(connection.bitmap, PageSegMode.Auto); | |
pictureBox1.Image = connection.bitmap; | |
Read = page.GetText(); | |
} | |
catch { } | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
connection.videoCapture = new VideoCapture("http://172.20.10.5:4747/mjpegfeed?340x280"); | |
connection.imageViewer = new ImageViewer(); | |
Thread.Sleep(TimeSpan.FromSeconds(5)); | |
connection.Connected = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment