-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
28602
authored and
28602
committed
Sep 16, 2024
1 parent
6931fd5
commit a0d1701
Showing
12 changed files
with
661 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.3.32901.215 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonCSharpProj", "PythonCSharpProj\PythonCSharpProj.csproj", "{018366AA-E62A-4326-AF3F-221A4D660A13}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{018366AA-E62A-4326-AF3F-221A4D660A13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{018366AA-E62A-4326-AF3F-221A4D660A13}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{018366AA-E62A-4326-AF3F-221A4D660A13}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{018366AA-E62A-4326-AF3F-221A4D660A13}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {E89B8256-394C-4396-B286-44E0BB71F953} | ||
EndGlobalSection | ||
EndGlobal |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace PythonCSharpProj | ||
{ | ||
public partial class Form1 : Form | ||
{ | ||
public Form1() | ||
{ | ||
InitializeComponent(); | ||
/*pictureBox1.MouseMove += pictureBox1.pictureBox_MouseMove; | ||
pictureBox1.MouseDown += pictureBox1.pictureBox_MouseDown; | ||
pictureBox1.MouseWheel += pictureBox1.pictureBox_MouseWheel; | ||
pictureBox1.Paint += pictureBox1.pictureBox_Paint;*/ | ||
Init(); | ||
} | ||
|
||
private void Init() | ||
{ | ||
string pyDllPath = @"C:\Users\28602\AppData\Local\Programs\Python\Python310\python310.dll"; | ||
string PyPath = @"G:\PythonCSharp\PythonCSharpProj\PythonCSharpProj\PythonCode"; | ||
PyInterface.SetPyEnvironment(pyDllPath, PyPath); | ||
} | ||
|
||
private void button1_Click(object sender, EventArgs e) | ||
{ | ||
byte[] imageBytes = PyInterface.CallPythonMethod<byte[]>("testFunc", "TestFunc", new object[] {"111222"}, LogMsg); | ||
pictureBox1.Image = Image.FromStream(new MemoryStream(imageBytes)); | ||
} | ||
|
||
private void LogMsg(object msg) | ||
{ | ||
richTextBox1.AppendText($"[Debug]{msg.ToString()}\n"); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<root> | ||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
<xsd:complexType> | ||
<xsd:choice maxOccurs="unbounded"> | ||
<xsd:element name="metadata"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" use="required" type="xsd:string" /> | ||
<xsd:attribute name="type" type="xsd:string" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="assembly"> | ||
<xsd:complexType> | ||
<xsd:attribute name="alias" type="xsd:string" /> | ||
<xsd:attribute name="name" type="xsd:string" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="data"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="resheader"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:choice> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>2.0</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
</root> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using OpenCvSharp; | ||
using OpenCvSharp.Extensions; | ||
|
||
namespace PythonCSharpProj | ||
{ | ||
class PictureBoxEX : PictureBox | ||
{ | ||
private int LURow = 0; | ||
private int LUCol = 0; | ||
public int RealWidth = 0; | ||
public int RealHeight = 0; | ||
public Mat srcImage = new Mat(); | ||
public Mat showImage = new Mat(); | ||
|
||
public int srcWidth, srcHeight = 0; | ||
public OpenCvSharp.Point CurrentPoint = new OpenCvSharp.Point(0, 0); | ||
public OpenCvSharp.Point EndPoint = new OpenCvSharp.Point(0, 0); | ||
System.Drawing.Point p = new System.Drawing.Point(0, 0); | ||
public int w_empty = 0; | ||
public int h_empty = 0; | ||
|
||
|
||
public void pictureBox_MouseMove(object? sender, MouseEventArgs e) | ||
{ | ||
if (Image == null) return; | ||
|
||
if (e.Button == MouseButtons.Left) | ||
{ | ||
EndPoint = GetImagePoint(e.Location); | ||
|
||
int offsetX = EndPoint.X - CurrentPoint.X; | ||
int offsetY = EndPoint.Y - CurrentPoint.Y; | ||
LURow -= offsetY; | ||
LUCol -= offsetX; | ||
judgeBounds(); | ||
showImage = new Mat(srcImage, new Rect(LUCol, LURow, RealWidth, RealHeight)); | ||
|
||
} | ||
else | ||
{ | ||
CurrentPoint = GetImagePoint(e.Location); | ||
} | ||
} | ||
|
||
public void pictureBox_MouseDown(object? sender, MouseEventArgs e) | ||
{ | ||
if (Image == null) return; | ||
CurrentPoint = GetImagePoint(e.Location); | ||
|
||
} | ||
|
||
|
||
public void pictureBox_MouseWheel(object? sender, MouseEventArgs e) | ||
{ | ||
if (Image == null) return; | ||
if (e.Delta > 0) | ||
{ | ||
RealWidth /= 2; | ||
RealHeight /= 2; | ||
LUCol = CurrentPoint.X - (int)RealWidth / 2; | ||
LURow = CurrentPoint.Y - (int)RealHeight / 2; | ||
} | ||
else | ||
{ | ||
RealWidth *= 2; | ||
RealHeight *= 2; | ||
LUCol = CurrentPoint.X - (int)RealWidth / 2; | ||
LURow = CurrentPoint.Y - (int)RealHeight / 2; | ||
|
||
} | ||
|
||
judgeBounds(); | ||
showImage = new Mat(srcImage, new Rect(LUCol, LURow, RealWidth, RealHeight)); | ||
|
||
} | ||
|
||
private void judgeBounds() | ||
{ | ||
RealWidth = RealWidth <= 1 ? 1 : (RealWidth > srcWidth ? srcWidth : RealWidth); | ||
RealHeight = RealHeight <= 1 ? 1 : (RealHeight > srcHeight ? srcHeight : RealHeight); | ||
LUCol = LUCol <= 0 ? 0 : (LUCol > srcImage.Width - RealWidth ? srcImage.Width - RealWidth : LUCol); | ||
LURow = LURow <= 0 ? 0 : (LURow > srcImage.Height - RealHeight ? srcImage.Height - RealHeight : LURow); | ||
} | ||
|
||
private OpenCvSharp.Point GetImagePoint(System.Drawing.Point p) | ||
{ | ||
OpenCvSharp.Point imagePoint; | ||
int width = showImage.Width; | ||
int height = showImage.Height; | ||
int w = Width; int h = Height; | ||
double ratio; | ||
if (w_empty > 0) | ||
{ | ||
ratio = h * 1.0 / height; | ||
|
||
if (p.X < w_empty || p.X > w - w_empty) | ||
imagePoint.X = -1; | ||
else | ||
imagePoint.X = LUCol + (int)((p.X - w_empty) * 1.0 / ratio); | ||
imagePoint.Y = LURow + (int)(p.Y * 1.0 / ratio); | ||
} | ||
else | ||
{ | ||
ratio = w * 1.0 / width; | ||
|
||
imagePoint.X = LUCol + (int)(p.X * 1.0 / ratio); | ||
if (p.Y < h_empty || p.Y > h - h_empty) | ||
imagePoint.Y = -1; | ||
else | ||
imagePoint.Y = LURow + (int)((p.Y - h_empty) * 1.0 / ratio); | ||
} | ||
return imagePoint; | ||
} | ||
|
||
public void pictureBox_Paint(object? sender, PaintEventArgs e) | ||
{ | ||
if (Image == null) | ||
return; | ||
var state = e.Graphics.Save(); | ||
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; | ||
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; | ||
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; | ||
e.Graphics.Clear(BackColor); | ||
if (h_empty != 0) | ||
e.Graphics.DrawImage(Image, 0, h_empty, Width, Height - 2 * h_empty); | ||
else | ||
e.Graphics.DrawImage(Image, w_empty, 0, Width - 2 * w_empty, Height); | ||
e.Graphics.Restore(state); | ||
} | ||
} | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace PythonCSharpProj | ||
{ | ||
internal static class Program | ||
{ | ||
/// <summary> | ||
/// The main entry point for the application. | ||
/// </summary> | ||
[STAThread] | ||
static void Main() | ||
{ | ||
// To customize application configuration such as set high DPI settings or default font, | ||
// see https://aka.ms/applicationconfiguration. | ||
ApplicationConfiguration.Initialize(); | ||
Application.Run(new Form1()); | ||
} | ||
} | ||
} |
Oops, something went wrong.