modified: qrCamera/Program.cs

This commit is contained in:
Kq
2026-08-12 19:41:53 +02:00
parent 66ba176204
commit 90120ee2cd
+36 -19
View File
@@ -9,6 +9,7 @@ using System.Drawing;
using System.Net;
using System.Runtime.InteropServices.Marshalling;
using Emgu.CV.Face;
using System.Transactions;
// using Emgu.CV.CvEnum;
@@ -17,6 +18,7 @@ namespace BarcodeReaderExample
{
class Program
{
static bool draw;
static void Main(string[] args)
{
VideoCapture camera = new VideoCapture("/dev/video0", VideoCaptureAPIs.V4L2);
@@ -37,7 +39,7 @@ namespace BarcodeReaderExample
Directory.CreateDirectory("cache");
Mat hey = new Mat("photo.png");
Mat[] Cached = new Mat[avalibeImages];
draw = true;
int imgX = 0;
int imgY = 0;
@@ -56,7 +58,7 @@ namespace BarcodeReaderExample
Mat Lastimage = new Mat();
IEnumerable<IEnumerable<OpenCvSharp.Point>> contours = null;
// PointF[] location;
Mat previue = new Mat();
string[] files = new string[avalibeImages];
int files_index = 0;
while (true)
@@ -69,9 +71,10 @@ namespace BarcodeReaderExample
// Console.WriteLine(Lastimage.Empty());
if (!(Lastimage.Empty()))
{
Mat roi2 = frame[new Rect(0, 0, Lastimage.Width, Lastimage.Height)];
Lastimage.CopyTo(roi2);
Cv2.Resize(Lastimage, previue, new OpenCvSharp.Size(500, 500));
Mat roi2 = frame[new Rect(0, 0, previue.Width, previue.Height)];
previue.CopyTo(roi2);
}
if (result != null)
@@ -109,8 +112,8 @@ namespace BarcodeReaderExample
imgY = GetPoint(location[0]).Y;
contours = new[] { points1 };
Cv2.FillPoly(frame, contours, Scalar.White); // fill with white
if (draw)
Cv2.FillPoly(frame, contours, Scalar.White); // fill with white
//Write Text
// Cv2.PutText(frame, result.Text, new OpenCvSharp.Point((int)(pos2[0]-pos3[0])/2+(int)pos3[0]-160, (int)(pos2[1]-pos3[1])/2+(int)pos3[1]+60), HersheyFonts.HersheySimplex, 0.8, Scalar.Black, 2);
@@ -145,17 +148,19 @@ namespace BarcodeReaderExample
Cv2.Resize(Cached[toload],toDraw,new OpenCvSharp.Size(qrWidth,qrHeigh));
}
catch
{continue;}
{ continue; }
Lastimage = toDraw;
// toDraw.Resize(1,3);
try
{
Mat roi2 = frame[new Rect(GetPoint(location[0]).X, GetPoint(location[0]).Y, toDraw.Width, toDraw.Height)];
toDraw.CopyTo(roi2);
// Mat roi2 = frame[new Rect(GetPoint(location[0]).X, GetPoint(location[0]).Y, toDraw.Width, toDraw.Height)];
// toDraw.CopyTo(roi2);
DrawImage(toDraw, GetPoint(location[0]).X, GetPoint(location[0]).Y);
}
catch{}
catch { }
}
@@ -165,12 +170,14 @@ namespace BarcodeReaderExample
{
Cv2.FillPoly(frame, contours, Scalar.White); // fill with white
try
{
Mat roi2 = frame[new Rect(imgX, imgY, Lastimage.Width, Lastimage.Height)];
Lastimage.CopyTo(roi2);
}
catch{}
try
{
// Mat roi2 = frame[new Rect(imgX, imgY, Lastimage.Width, Lastimage.Height)];
// Lastimage.CopyTo(roi2);
DrawImage(Lastimage,imgX,imgY);
}
catch { }
whenWasLastTimeQrDetected--;
}
@@ -188,8 +195,14 @@ namespace BarcodeReaderExample
}
static void rotate()
static void DrawImage(Mat image, int posX, int posY)
{
if(draw)
{
Mat roi2 = frame[new Rect(posX, posY, image.Width, image.Height)];
image.CopyTo(roi2);
}
}
static OpenCvSharp.Point GetPoint(PointF pointf)
{
@@ -239,7 +252,11 @@ namespace BarcodeReaderExample
}
static void DrawLine(PointF p1, PointF p2)
{
if(draw)
{
Cv2.Line(frame, (int)p1.X, (int)p1.Y, (int)p2.X, (int)p2.Y, Scalar.Red, 2);
}
}
static void DrawLine(PointF[] Location)