3 Commits
Author SHA1 Message Date
Kq 4059a3b67b update 2026-08-12 19:11:44 +02:00
Kq e6a8c2f6e5 update 2026-08-12 18:12:30 +02:00
Kq edd9797246 modified: .gitignore
new file:   Makefile
2026-08-12 17:46:33 +02:00
5 changed files with 104 additions and 75 deletions
+5 -3
View File
@@ -1,5 +1,7 @@
/bin /qrCamera/bin
/obj /qrCamera/obj
/cache /qrCamera/cache
/createqrcodes/bin /createqrcodes/bin
/createqrcodes/obj /createqrcodes/obj
/qr
/createqr
+13
View File
@@ -0,0 +1,13 @@
qr:
dotnet publish createqrcodes/createqrcodes.csproj -p:PublishSingleFile=true
mv createqrcodes/bin/Release/net10.0/linux-x64/publish/createqrcodes ./createqr
clean:
rm -rf qrCamera/bin/
rm -rf qrCamera/obj/
rm -rf createqrcodes/obj/
rm -rf createqrcodes/bin/
rm -f createqr
rm -rf qr/
run:
dotnet run -p:qrCamera/CameraPreview.csproj
+2 -1
View File
@@ -12,5 +12,6 @@ foreach (var item in files)
string name = Path.GetFileName(item); string name = Path.GetFileName(item);
//https://gitea.kqnori.pl/kq/qrcode/raw/branch/main/assets/gay.png //https://gitea.kqnori.pl/kq/qrcode/raw/branch/main/assets/gay.png
Process.Start("qrencode",$"https://gitea.kqnori.pl/kq/qrcode/raw/branch/main/assets/{item} -o qr/item{name.Split('.').First()}.png"); Console.WriteLine(name);
Process.Start("qrencode",$"https://gitea.kqnori.pl/kq/qrcode/raw/branch/main/assets/{name} -o qr/item{name.Split('.').First()}.png");
} }
+76 -63
View File
@@ -7,6 +7,8 @@ using ZXing.Common;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Drawing; using System.Drawing;
using System.Net; using System.Net;
using System.Runtime.InteropServices.Marshalling;
using Emgu.CV.Face;
// using Emgu.CV.CvEnum; // using Emgu.CV.CvEnum;
@@ -24,7 +26,8 @@ namespace BarcodeReaderExample
camera.Set(VideoCaptureProperties.FrameWidth, 1280); camera.Set(VideoCaptureProperties.FrameWidth, 1280);
camera.Set(VideoCaptureProperties.FrameHeight, 720); camera.Set(VideoCaptureProperties.FrameHeight, 720);
camera.Set(VideoCaptureProperties.Fps, 24); int fps = 60;
camera.Set(VideoCaptureProperties.Fps, fps);
if (Directory.Exists("cache")) if (Directory.Exists("cache"))
{ {
Directory.Delete("cache", true); Directory.Delete("cache", true);
@@ -35,6 +38,9 @@ namespace BarcodeReaderExample
Mat[] Cached = new Mat[10]; Mat[] Cached = new Mat[10];
int imgX = 0;
int imgY = 0;
using var rgb = new Mat(); using var rgb = new Mat();
// OpenCV stores camera frames as BGR. // OpenCV stores camera frames as BGR.
@@ -44,35 +50,39 @@ namespace BarcodeReaderExample
Cv2.NamedWindow("Camera preview", WindowFlags.AutoSize); Cv2.NamedWindow("Camera preview", WindowFlags.AutoSize);
int photocount = 0; // Mat src = Cv2.ImRead("test.png");
Mat src = Cv2.ImRead("test.png"); int whenWasLastTimeQrDetected = 0;
Mat Lastimage = new Mat();
IEnumerable<IEnumerable<OpenCvSharp.Point>> contours = null;
// PointF[] location;
string[] files = new string[20];
string[] files = new string[10];
int files_index = 0; int files_index = 0;
while (true) while (true)
{ {
// if (!camera.Read(frame) || frame.Empty())
// {
// Console.Error.WriteLine("Nie udało się odczytać klatki");
// break;
// }
camera.Read(frame); camera.Read(frame);
Result result = ReadQrCode(frame);
Console.WriteLine(Lastimage.Empty());
if (!(Lastimage.Empty()))
{
Mat roi2 = frame[new Rect(0, 0, Lastimage.Width, Lastimage.Height)];
Lastimage.CopyTo(roi2);
}
Result result = GetResult(frame);
if (result != null) if (result != null)
{ {
whenWasLastTimeQrDetected = 5;
List<ResultPoint> points = result.ResultPoints.ToList(); List<ResultPoint> points = result.ResultPoints.ToList();
float[] pos1 = new float[2] { points[0].X, points[0].Y }; /// lewy dolny róg float[] pos1 = new float[2] { points[0].X, points[0].Y }; /// lewy dolny róg
float[] pos2 = new float[2] { points[2].X, points[2].Y }; ///prawy górny róg float[] pos2 = new float[2] { points[2].X, points[2].Y }; ///prawy górny róg
float[] pos3 = new float[2] { points[1].X, points[1].Y }; ///lewy górny róg float[] pos3 = new float[2] { points[1].X, points[1].Y }; ///lewy górny róg
int width = (int)(pos2[0] - pos3[0]); int width = (int)(pos2[0] - pos3[0]);
int heigh = (int)(pos1[1] - pos3[1]); int heigh = (int)(pos1[1] - pos3[1]);
// Cv2.Circle(frame, (int)pos1[0], (int)pos1[1], 5, Scalar.Red, 2);
// Cv2.Circle(frame, (int)pos2[0], (int)pos2[1], 5, Scalar.Green, 2);
// Cv2.Circle(frame, (int)pos3[0], (int)pos3[1], 5, Scalar.Blue, 2);
PointF[] location; PointF[] location;
try try
{ {
@@ -83,19 +93,6 @@ namespace BarcodeReaderExample
{ {
continue; continue;
} }
// Mat roi = frame[new Rect((int)pos3[0],(int)pos3[1], src.Width+3, src.Height)];
Mat roi = frame[new Rect((int)pos3[0], (int)pos3[1], width,heigh)];
src.CopyTo(roi);
// Console.WriteLine($"szerokość:{width}");
// Console.WriteLine($"wysokosc:{heigh}");
// Console.WriteLine($"x:{pos3[0]}");
// Console.WriteLine($"y:{pos3[1]}");
// DrawLine(location); //draw red squre
var points1 = new List<OpenCvSharp.Point> var points1 = new List<OpenCvSharp.Point>
{ {
GetPoint(location[0]), GetPoint(location[0]),
@@ -103,14 +100,19 @@ namespace BarcodeReaderExample
GetPoint(location[3]), GetPoint(location[3]),
GetPoint(location[2]) GetPoint(location[2])
}; };
int qrWidth = GetPoint(location[1]).X - GetPoint(location[0]).X;
// Zagnieźdź w dodatkową kolekcję: int qrHeigh = GetPoint(location[2]).Y - GetPoint(location[0]).Y;
IEnumerable<IEnumerable<OpenCvSharp.Point>> contours = new[] { points1 };
// Cv2.FillPoly(frame, contours, Scalar.White); // fill with white imgX = GetPoint(location[0]).X;
imgY = GetPoint(location[0]).Y;
contours = new[] { points1 };
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.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);
if (!files.Contains(result.Text)) if (!files.Contains(result.Text))
{ {
@@ -128,37 +130,54 @@ namespace BarcodeReaderExample
} }
else else
{ {
// try
// {
int toload = files.IndexOf(result.Text); int toload = files.IndexOf(result.Text);
Mat toDraw= new Mat();
InputArray inputArray = toDraw;
// Console.WriteLine($"{qrWidth} , {qrHeigh}");
try
{
Cv2.Resize(Cached[toload],toDraw,new OpenCvSharp.Size(qrWidth,qrHeigh));
}
catch
{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);
}
catch{}
Mat roi2 = frame[new Rect((int)pos3[0], (int)pos3[1], Cached[toload].Width, Cached[toload].Height)];
Cached[toload].CopyTo(roi2);
// Console.WriteLine("work");
// }
// catch { }
} }
// Cv2.draw
// Cv2.Circle(frame, (int)(RightBottomX), (int)(RightBottomY), 5, Scalar.Green, 2);
//Cv2.Rectangle(frame, new Point((int)X, (int)Y), new Point ((int)Width, (int)Height), Scalar.Red, 2);
// Console.WriteLine(result.Text);
} }
else if (whenWasLastTimeQrDetected > 0)
{
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{}
whenWasLastTimeQrDetected--;
}
// frame.SaveImage($"photos/photo_{photocount}.png");
// photocount++;
Cv2.ImShow("Camera preview", frame); Cv2.ImShow("Camera preview", frame);
Thread.Sleep(1000 / 24); Thread.Sleep(1000 / fps);
// Console.WriteLine("tick");
int key = Cv2.WaitKey(1); int key = Cv2.WaitKey(1);
if (key == 27 || key == 'q') if (key == 27 || key == 'q')
break; break;
@@ -167,6 +186,10 @@ namespace BarcodeReaderExample
Cv2.DestroyAllWindows(); Cv2.DestroyAllWindows();
} }
static void rotate()
{
}
static OpenCvSharp.Point GetPoint(PointF pointf) static OpenCvSharp.Point GetPoint(PointF pointf)
{ {
return new OpenCvSharp.Point(pointf.X, pointf.Y); return new OpenCvSharp.Point(pointf.X, pointf.Y);
@@ -234,7 +257,7 @@ namespace BarcodeReaderExample
} }
static Mat frame = new Mat(); static Mat frame = new Mat();
static Result GetResult(Mat frame) static Result ReadQrCode(Mat frame)
{ {
QRCodeReader reader = new QRCodeReader(); QRCodeReader reader = new QRCodeReader();
@@ -288,13 +311,3 @@ namespace BarcodeReaderExample
} }
} }