modified: qrCamera/Program.cs

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