C# Grabber Service選取GrabberService專案按下滑鼠右鍵並選取管理NuGet套件安裝Newtonsoft.Json套件專案新增appsettings.json選取GrabberService專案按下滑鼠右鍵並選取"加入",接著選取"新增項目"輸入名稱: appsettings.json滑鼠雙擊開啟appsettings.jsonGrabberService/FrameHeader.csusing System.Runtime.InteropServices;
namespace GrabberService;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct FrameHeader
{
public ulong FrameId;
public ulong TimestampNs;
public uint Width;
public uint Height;
public uint Stride;
public uint PixelFormat;
public uint ImageSize;
public uint CameraIndex;
public uint Flags;
}

me1237guy 發表在 痞客邦 留言(0) 人氣()

今天測試同步播放兩支影片






 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89



using System;
using System.Threading;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using System.Windows.Forms;

namespace WaferPositioning
{
// 同時播放兩支影片
public class DualVideoPlayer
{
private VideoCapture capture1;
private VideoCapture capture2;
private ManualResetEvent pauseEvent = new ManualResetEvent(true);
private bool stopThreads = false;

public event EventHandler<FrameReadyEventArgs> FrameReady;

public DualVideoPlayer(string videoFile1, string videoFile2)
{
capture1 = new VideoCapture(videoFile1);
capture2 = new VideoCapture(videoFile2);
}

public void Start()
{
stopThreads = false;
pauseEvent.Set(); // Resume if paused
ThreadPool.QueueUserWorkItem(o => StartVideoPlayback());
}

public void Pause()
{
pauseEvent.Reset(); // Pause playback
}

public void Resume()
{
pauseEvent.Set(); // Resume playback
}

public void Stop()
{
stopThreads = true;
pauseEvent.Set(); // Resume if paused
}

private void StartVideoPlayback()
{
while (!stopThreads)
{
pauseEvent.WaitOne(); // Pause if signaled

Mat frame1 = new Mat();
Mat frame2 = new Mat();

// Read frames from the video captures
capture1.Read(frame1);
capture2.Read(frame2);

if (!frame1.IsEmpty && !frame2.IsEmpty)
{
FrameReady?.Invoke(this, new FrameReadyEventArgs(frame1, frame2));
}
else
{
// End of video, you may want to stop or loop the playback
capture1.Set(CapProp.PosFrames, 0);
capture2.Set(CapProp.PosFrames, 0);
}
Thread.Sleep(33);
Application.DoEvents(); // Allow UI events to be processed
}
}
}

public class FrameReadyEventArgs : EventArgs
{
public Mat Frame1 { get; }
public Mat Frame2 { get; }

public FrameReadyEventArgs(Mat frame1, Mat frame2)
{
Frame1 = frame1;
Frame2 = frame2;
}
}
}





me1237guy 發表在 痞客邦 留言(0) 人氣()



編輯應用程式 App.config

 

me1237guy 發表在 痞客邦 留言(0) 人氣()


 
下載 .NET 7.0 x64

me1237guy 發表在 痞客邦 留言(0) 人氣()


nuGet管理套件安裝
1. SQLite

me1237guy 發表在 痞客邦 留言(1) 人氣()

image

 1: static void Main(string[] args)
 2: {
 3: var v1 = f1();
 4: var avg1 = v1 / 3;
 5: Console.WriteLine($"{avg1.GetType().Name}, avg: {avg1}");
 6:  
 7: var v2 = f2();
 8: var avg2 = v2 / 3;
 9: Console.WriteLine($"{avg2.GetType().Name}, avg: {avg2}");
 10:  
 11: var v3 = f3();
 12: var avg3 = v3 / 3;
 13: Console.WriteLine($"{avg3.GetType().Name}, avg: {avg3}");
 14:  
 15: var v4 = f4();
 16: var avg4 = v4 / 3;
 17: Console.WriteLine($"{avg4.GetType().Name}, avg: {avg4}");
 18:  
 19: var v5 = f5();
 20: var avg5 = v5 / 3;
 21: Console.WriteLine($"{avg5.GetType().Name}, avg: {avg5}");
 22: Console.ReadKey();
 23: }
 24: static double f1()
 25: {
 26: double x = 100;
 27: return x;
 28: }
 29: static float f2()
 30: {
 31: float x = 100;
 32: return x;
 33: }
 34: static decimal f3()
 35: {
 36: decimal x = 100;
 37: return x;
 38: }
 39: static long f4()
 40: {
 41: long x = 100;
 42: return x;
 43: }
 44: static Int32 f5()
 45: {
 46: Int32 x = 100;
 47: return x;
 48: }

me1237guy 發表在 痞客邦 留言(0) 人氣()

C# call a c++ method, which is called GetSourceImage(…)The following is the way how we get the bitmap data by copying srcBmpData to dstBmpdata, and showing them on a pictureBox.The copy sequence is just the same as OpenCV BGR, it looks as though we create a Format32bppArgb image. ,
 1: this.Invoke((MethodInvoker)delegate
 2: {
 3: int width, height, channel, step;
 4: unsafe
 5: {
 6: byte* srcBmpData = cVideo.GetSourceImage(&width, &height, &channel, &step);
 7: Result_lbl.Text = $"{width},{height},{channel},{step}";
 8: Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
 9: var data = bmp.LockBits(new Rectangle(0, 0, width, height),
 10: System.Drawing.Imaging.ImageLockMode.WriteOnly,
 11: System.Drawing.Imaging.PixelFormat.Format32bppRgb);
 12: byte* dstBmpData = (byte*)data.Scan0.ToPointer();
 13: int hei = height;
 14: int wid = width;
 15: int stepsize = step;
 16: 
 17:  
 18: for (int y = 0; y < height; y++)
 19: {
 20: for (int x = 0; x < width; x++)
 21: {
 22: dstBmpData[y * width * 4 + 4 * x] = srcBmpData[y * step + channel * x];
 23: dstBmpData[y * width * 4 + 4 * x + 1] = srcBmpData[y * step + channel * x + 1];
 24: dstBmpData[y * width * 4 + 4 * x + 2] = srcBmpData[y * step + channel * x + 2];
 25: }
 26: }
 27: bmp.UnlockBits(data);
 28: pictureBox1.Image = bmp;
 29: }

30: });


me1237guy 發表在 痞客邦 留言(0) 人氣()

以下根據 DKTD-WinFormThreading 文章節錄重點
1.自己建立thread優點: 精確管理thread生命週期缺點: 執行緒數目過多時
,CPU會耗費太多的資源處理Context Switching

me1237guy 發表在 痞客邦 留言(0) 人氣()

image

 1:  
 2: enum Animal
 3: {
 4: Dog = 0x0001,
 5: Cat = 0x0002,
 6: Duck = 0x0004,
 7: Chicken = 0x0008
 8: }
 9: static void Main(string[] args)
 10: {
 11: Animal animals = Animal.Dog | Animal.Cat;
 12: Console.WriteLine(animals.ToString());
 13: Console.ReadKey();
 14: }

me1237guy 發表在 痞客邦 留言(0) 人氣()

先說結論:  readonly比較不會出錯,一般狀況新版的dll蓋過去就好,但如果是const狀況,須將整個專案重新編譯,才不會出錯!
參考資料:[C#.NET] 定義常數時用 readonly 好? 還是 const 好?

me1237guy 發表在 痞客邦 留言(0) 人氣()

Serialization is used to write class objects to files.[1] De-Serialization is used to recover the objects from the file.
When we want to transport an object through network then we have to convert the object into a stream of bytes.[2] The process of converting an object into a stream of bytes is called Serialization. For an object to be serializable, it should implement ISerialize Interface. De-serialization is the reverse process of creating an object from a stream of bytes.
參考資料:1. C# Serialization & Deserialization with Example

me1237guy 發表在 痞客邦 留言(0) 人氣()

參考資料1. SQLite 資料庫 C# 程式範例-使用 Dapper

me1237guy 發表在 痞客邦 留言(0) 人氣()

Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。