Browse Source

20240122

20230911
Денис Кузнецов 2 years ago
parent
commit
ca42a9b64d
  1. 166
      piv.cs
  2. 64
      udplib.cs
  3. 27
      util.cs

166
piv.cs

@ -1,9 +1,13 @@ @@ -1,9 +1,13 @@
using System;
#define VLADIMIR
using System;
using UTIL;
/// <summary>
/// Ноавя версия ПИВ 1.23
/// </summary>
namespace PIV
{
public static class CONST
@ -2182,6 +2186,12 @@ namespace PIV @@ -2182,6 +2186,12 @@ namespace PIV
/// </summary>
public static class AZUM
{
public static int WF { get => (int)Wfull; set => Wfull = (double)value; }
public static int HF { get => (int)Hfull; set => Hfull = (double)value; }
private static Double Wfull; // = (Double)WF;
private static Double Hfull; // = (Double)HF;
//const Double Wfull = 4072.0;
//const Double Hfull = 3064.0;
/*
private static void pix2ang()
{
@ -2272,31 +2282,41 @@ namespace PIV @@ -2272,31 +2282,41 @@ namespace PIV
//% w - количество столбцов изображения
//% h - количество строк изображения
//sAZUM retu;
if (WF == 0 || HF == 0)
{
throw new Exception("Не заданы значения размера матрицы!");
}
Double w_full = Wfull;
Double h_full = Hfull;
Double w_full = 4072.0;
Double h_full = 3064.0;
//#if DEBUG
// Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}");
//#endif
#if VLADIMIR
Double focus_meters = 27.5e-3;
Double pixel_size_meters = 3.2e-6; //22.5''
#else
Double focus_meters = 12e-3;
Double pixel_size_meters = 1.55e-6;
#endif
Double rad2deg = (180.0 / (Double)Math.PI);
Double f = focus_meters / pixel_size_meters;
//Double xc_full = 0.5f * w_full;
//Double yc_full = 0.5f * h_full;
Double xc_full = 0.5f * w_full;
Double yc_full = 0.5f * h_full;
Double yc_full = (6.0 / 42.0) * h_full;
Double x_full = (X + 0.5) * w_full / W;
Double y_full = (Y + 0.5) * h_full / H;
Double x_ohf = x_full - xc_full;
Double y_ohf = y_full - yc_full;
Double z_ohf = f;
Double rho = (Double)Math.Sqrt(x_ohf * x_ohf + z_ohf * z_ohf);
A = (Double)Math.Atan2(x_ohf, z_ohf) * rad2deg;
U = (Double)(-Math.Atan2(y_ohf, rho) * rad2deg);
}
public static void pix2ang(ref float A, ref float U, float W, float H, float X, float Y)
public static void p2a(ref Double A, ref Double U, Double W, Double H, Double X, Double Y)
{
//% (x, y) - координаты центра пикселя изображения
//% начало O = (0, 0) системы координат изображения находится
@ -2307,18 +2327,75 @@ namespace PIV @@ -2307,18 +2327,75 @@ namespace PIV
//% w - количество столбцов изображения
//% h - количество строк изображения
//sAZUM retu;
if (WF == 0 || HF == 0)
{
throw new Exception("Не заданы значения размера матрицы!");
}
Double w_full = Wfull;
Double h_full = Hfull;
float w_full = (float)4072.0;
float h_full = (float)3064.0;
//#if DEBUG
// Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}");
//#endif
#if VLADIMIR
Double focus_meters = 27.5e-3;
Double pixel_size_meters = 3.2e-6; //22.5''
#else
Double focus_meters = 12e-3;
Double pixel_size_meters = 1.55e-6;
#endif
Double rad2deg = (180.0 / (Double)Math.PI);
Double f = focus_meters / pixel_size_meters;
//Double xc_full = 0.5f * w_full;
//Double yc_full = 0.5f * h_full;
float focus_meters = 12e-3F;
float pixel_size_meters = 1.55e-6F;
Double xc_full = 0.5f * w_full;
Double yc_full = (6.0 / 42.0) * h_full;
float rad2deg = (180.0F / (float)Math.PI);
Double x_full = (X + 0.5) * w_full / W;
Double y_full = (Y + 0.5) * h_full / H;
Double x_ohf = x_full - xc_full;
Double y_ohf = y_full - yc_full;
Double z_ohf = f;
Double rho = (Double)Math.Sqrt(x_ohf * x_ohf + z_ohf * z_ohf);
A = (Double)Math.Atan2(x_ohf, z_ohf) * rad2deg;
U = (Double)(-Math.Atan2(y_ohf, rho) * rad2deg);
}
public static void pix2ang(ref float A, ref float U, float W, float H, float X, float Y)
{
//% (x, y) - координаты центра пикселя изображения
//% начало O = (0, 0) системы координат изображения находится
//% в центре левого верхнего пикселя
//% ось OX направлена вправо по возрастанию номеров столбцов
//% ось OY направлена вниз по возрастанию номеров строк
//%
//% w - количество столбцов изображения
//% h - количество строк изображения
//sAZUM retu;
if (WF == 0 || HF == 0)
{
throw new Exception("Не заданы значения размера матрицы!");
}
float w_full = (float)Wfull;
float h_full = (float)Hfull;
//#if DEBUG
// Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}");
//#endif
#if VLADIMIR
float focus_meters = 27.5e-3F;
float pixel_size_meters = 3.2e-6F; //22.5''
#else
float focus_meters = 12e-3;
float pixel_size_meters = 1.55e-6;
#endif
float rad2deg = (180.0F / (float)Math.PI);
float f = focus_meters / pixel_size_meters;
//float xc_full = 0.5f * w_full;
//float yc_full = 0.5f * h_full;
float xc_full = 0.5f * w_full;
float yc_full = 0.5f * h_full;
float yc_full = (6.0F / 42.0F) * h_full;
float x_full = (float)(X + 0.5) * w_full / W;
float y_full = (float)(Y + 0.5) * h_full / H;
@ -2345,17 +2422,29 @@ namespace PIV @@ -2345,17 +2422,29 @@ namespace PIV
//% w - количество столбцов изображения, double
//% h - количество строк изображения, double
Double w_full = (Double)(4072);
Double h_full = (Double)(3064);
Double focus_meters = (Double)(12e-3);
Double pixel_size_meters = (Double)(1.55e-6);
if (WF == 0 || HF == 0)
{
throw new Exception("Не заданы значения размера матрицы!");
}
Double w_full = (Double)Wfull;
Double h_full = (Double)Hfull;
//#if DEBUG
// Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}");
//#endif
#if VLADIMIR
Double focus_meters = 27.5e-3;
Double pixel_size_meters = 3.2e-6; //22.5''
#else
Double focus_meters = 12e-3;
Double pixel_size_meters = 1.55e-6;
#endif
Double deg2rad = (Double)(Math.PI / 180.0); //% pi = 3.14...
//float rad2deg = (180.0f /3.1415926f);
Double f = focus_meters / pixel_size_meters;
Double xc_full = 0.5 * w_full;
Double yc_full = 0.5 * h_full;
//Double xc_full = 0.5 * w_full;
//Double yc_full = 0.5 * h_full;
Double xc_full = 0.5f * w_full;
Double yc_full = (6.0 / 42.0) * h_full;
//_au.A = _au.A * deg2rad;
//_au.U = _au.U * deg2rad;
@ -2387,17 +2476,32 @@ namespace PIV @@ -2387,17 +2476,32 @@ namespace PIV
//% w - количество столбцов изображения, double
//% h - количество строк изображения, double
float w_full = 4072F;
float h_full = 3064F;
if (WF == 0 || HF == 0)
{
throw new Exception("Не заданы значения размера матрицы!");
}
float w_full = (float)Wfull;
float h_full = (float)Hfull;
#if DEBUG
Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}");
#endif
float focus_meters = 12e-3F;
float pixel_size_meters = 1.55e-6F;
#if VLADIMIR
float focus_meters = 27.5e-3F;
float pixel_size_meters = 3.2e-6F; //22.5''
#else
float focus_meters = 12e-3;
float pixel_size_meters = 1.55e-6;
#endif
float deg2rad = (float)(Math.PI / 180.0); //% pi = 3.14...
//float rad2deg = (180.0f /3.1415926f);
float f = focus_meters / pixel_size_meters;
float xc_full = 0.5F * w_full;
float yc_full = 0.5F * h_full;
//float xc_full = 0.5F * w_full;
//float yc_full = 0.5F * h_full;
float xc_full = 0.5f * w_full;
float yc_full = (6.0F / 42.0F) * h_full;
//_au.A = _au.A * deg2rad;
//_au.U = _au.U * deg2rad;

64
udplib.cs

@ -17,7 +17,7 @@ namespace UDPLIB @@ -17,7 +17,7 @@ namespace UDPLIB
{
public class Data
{
public static string Ver = "1.1.2.264";
public static string Ver = "1.1.2.269";
protected static string IPAddr = "192.168.1.2";
protected static Int32 LocalPort = 5004;
protected static Int32 RemotePort = 5006;
@ -31,12 +31,8 @@ namespace UDPLIB @@ -31,12 +31,8 @@ namespace UDPLIB
public class UDPreceive : Data
{
//Int32 localPort = 5004;
//Int32 remotePort = 5006;
Thread UDPreceiveThread = null;
// Thread processFrameThread = null;
Thread sendFrameThread = null;
// Thread processDataFrameThread = null;
Stopwatch fpstimer;
private volatile bool listening = false;
UInt16 iwidth = 0;
@ -79,6 +75,7 @@ namespace UDPLIB @@ -79,6 +75,7 @@ namespace UDPLIB
public void Stop()
{
listening = false;
UDPreceiveThread.Abort();
cnt_frames = 0;
}
public Boolean IsAlive
@ -146,22 +143,12 @@ namespace UDPLIB @@ -146,22 +143,12 @@ namespace UDPLIB
}
if (numrow == 0 && ssrc == 12345678) // Packet 0
{
//iwidth = BitConverter.ToUInt16(data, 20);
//iheight = BitConverter.ToUInt16(data, 22);
blackline = new Byte[iwidth * 3 + 20];
RTP.DataH0 = data;
RTP.GetDataH0();
//Res.Iwidth = iwidth;
//Res.Iheight = iheight;
//Res.AzUpr = BitConverter.ToSingle(data, 24);
//Res.ElUpr = BitConverter.ToSingle(data, 28);
//Res.Course = BitConverter.ToInt16(data, 32);
//Res.Roll = BitConverter.ToInt16(data, 34);
//Res.Pitch = BitConverter.ToInt16(data, 36);
iwidth = RTP.SD_Width;
iheight = RTP.SD_Height;
@ -222,16 +209,25 @@ namespace UDPLIB @@ -222,16 +209,25 @@ namespace UDPLIB
}
catch (Exception ee)
{
#if DEBUG
using (StreamWriter sw = new StreamWriter(System.IO.File.OpenWrite("udplib.log")))
{
sw.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff ")} Error dll recv\r\n{ee.Message}");
}
#endif
}
}
receiver.Close();
Res.Fps = 0;
rrr2.Fps = 0;
Res.Lost = 0;
rrr2.Lost = 0;
CallBack.Event_newimg_Handler2(rrr2);
}
void processFrame7(object obj)
{
Int32 lost = 0;
UInt32 lostfix = 0;
try
{
thrdata arr = obj as thrdata;
@ -249,8 +245,27 @@ namespace UDPLIB @@ -249,8 +245,27 @@ namespace UDPLIB
udata.AddRange(udata51);
break;
}
//udata50.Clear();
//udata51.Clear();
iwi = BitConverter.ToUInt16(udata[0], 20);
ihe = BitConverter.ToUInt16(udata[0], 22);
// проверка потерянных строк
lost = 0;
lostfix = 0;
UInt32 ts = BitConverter.ToUInt32(udata[0], 4);
for (int i = 0; i < ihe; i++)
{
//Console.WriteLine($"{i}\t{udata[i].Length}");
if (BitConverter.ToUInt32(udata[i], 4) != ts)
lost++;
if (udata[i].Length == 0)
lostfix++;
}
Res.Lost = (float)lost / (float)ihe;
rrr2.Lost = (float)lost / (float)ihe;
Res.LostFix = lostfix;
rrr2.LostFix = lostfix;
//Console.WriteLine($"-Lost: {(float)lost / (float)ihe * 100:F4}% {lost} {ihe} {udata.Count}");
Bitmap img = new Bitmap(iwi, ihe, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Rectangle rect = new Rectangle(0, 0, iwi, ihe);
@ -310,10 +325,12 @@ namespace UDPLIB @@ -310,10 +325,12 @@ namespace UDPLIB
}
catch (Exception)
{
#if DEBUG
using (StreamWriter sw = new StreamWriter(System.IO.File.OpenWrite("udplib.log")))
{
sw.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff ") + "Error lib process");
}
#endif
}
}
#endregion
@ -328,19 +345,6 @@ namespace UDPLIB @@ -328,19 +345,6 @@ namespace UDPLIB
UInt16 pntlx = 0;
UInt16 pntly = 0;
//public UDPTransmit(String IPaddr, Int32 remotePortUDP, Point p)
//{
// transmitter = new UdpClient();
// endPoint = new IPEndPoint(IPAddress.Parse(IPaddr), remotePortUDP);
// pnt = p;
// pnt.X = Util.minmax((ushort)64, (ushort)576, (ushort)pnt.X);
// pnt.Y = Util.minmax((ushort)64, (ushort)416, (ushort)pnt.Y);
// Bitmap crop = Res.Clearimg.Clone(new Rectangle(pnt.X - 64, pnt.Y - 64, 128, 128), PixelFormat.Format24bppRgb);
// Res.Crop = crop;
// Thread UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame));
// UDPtransmitThread.Start();
//}
public UDPTransmit(String IPaddr, Int32 remotePortUDP, (UInt16, UInt16, UInt16, UInt16) p)
{
transmitter = new UdpClient();
@ -670,6 +674,8 @@ namespace UDPLIB @@ -670,6 +674,8 @@ namespace UDPLIB
public static UInt16 Iheight { set; get; }
public static UInt32 Frames { set; get; }
public static float Fps { set; get; }
public static float Lost { set; get; }
public static UInt32 LostFix { set; get; }
public static float AzUpr { set; get; }
public static float ElUpr { set; get; }
public static Int16 Course { set; get; }
@ -718,6 +724,8 @@ namespace UDPLIB @@ -718,6 +724,8 @@ namespace UDPLIB
public UInt16 Iwidth;
public UInt16 Iheight;
public UInt32 Frames;
public float Lost;
public UInt32 LostFix;
public float Fps;
public float AzUpr;
public float ElUpr;

27
util.cs

@ -251,13 +251,21 @@ namespace UTIL @@ -251,13 +251,21 @@ namespace UTIL
public static class S2B
{
#region Загрузка/выгрузка данных в структуру
//public static T BuffToStruct<T>(byte[] arr)
//{
// GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned);
// IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
// T ret = (T)Marshal.PtrToStructure(ptr, typeof(T));
// gch.Free();
// return default(T);
//}
public static T BuffToStruct<T>(byte[] arr)
{
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned);
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
T ret = (T)Marshal.PtrToStructure(ptr, typeof(T));
gch.Free();
return default(T);
GCHandle handle = GCHandle.Alloc(arr, GCHandleType.Pinned);
T stuff = (T)Marshal.PtrToStructure(
handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
return stuff;
}
public static T BuffToClass<T>(byte[] arr)
{
@ -580,11 +588,16 @@ namespace UTIL @@ -580,11 +588,16 @@ namespace UTIL
else
return DateTime.Now.ToString("HH:mm:ss ");
}
public static String printdatetime(Boolean ms)
{
if (ms == true)
return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff ");
else
return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ");
}
private const int EM_SETTABSTOPS = 0x00CB;
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam);
public static void SetTabWidth(TextBox textbox, int tabWidth)
{
Graphics graphics = textbox.CreateGraphics();

Loading…
Cancel
Save