158 lines
4.0 KiB
C#
158 lines
4.0 KiB
C#
using EloThermal.Properties;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
public class EloUVCCameraConverter
|
|
{
|
|
public static int UVC_WIDTH = 640;
|
|
public static int UVC_HEIGHT = 480;
|
|
|
|
public static int IR_WIDTH = 160;
|
|
public static int IR_HEIGHT = 120;
|
|
|
|
public static int IR_SCALED_WIDTH = 408;
|
|
public static int IR_SCALED_HEIGHT = 306;
|
|
|
|
public static float IR_SCALE = (float)IR_SCALED_HEIGHT / UVC_HEIGHT;
|
|
|
|
//(0,0) is at Left/Bottom
|
|
private static int CAMERAS_OFFSET_X = 81; //+:上面往左
|
|
private static int CAMERAS_OFFSET_Y = 65; //-:上面往上
|
|
|
|
public static Bitmap UVCBitmapWithIRSize(Bitmap uvcBitmap)
|
|
{
|
|
Rectangle rectSrc = new Rectangle(CAMERAS_OFFSET_X, UVC_HEIGHT - CAMERAS_OFFSET_Y - IR_SCALED_HEIGHT, IR_SCALED_WIDTH, IR_SCALED_HEIGHT);
|
|
Rectangle rectDest = new Rectangle(0, 0, IR_SCALED_WIDTH, IR_SCALED_HEIGHT);
|
|
|
|
Bitmap bmp = new Bitmap(IR_SCALED_WIDTH, IR_SCALED_HEIGHT, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
|
Graphics g = Graphics.FromImage(bmp);
|
|
g.DrawImage(uvcBitmap, rectDest, rectSrc, GraphicsUnit.Pixel);
|
|
g.Dispose();
|
|
return bmp;
|
|
|
|
}
|
|
public static Bitmap UVCBitmapWithIRWidth(Bitmap uvcBitmap)
|
|
{
|
|
Rectangle rectSrc = new Rectangle(CAMERAS_OFFSET_X, 0, IR_SCALED_WIDTH, UVC_HEIGHT);
|
|
Rectangle rectDest = new Rectangle(0, 0, IR_SCALED_WIDTH, UVC_HEIGHT);
|
|
|
|
Bitmap bmp = new Bitmap(IR_SCALED_WIDTH, UVC_HEIGHT, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
|
Graphics g = Graphics.FromImage(bmp);
|
|
g.DrawImage(uvcBitmap, rectDest, rectSrc, GraphicsUnit.Pixel);
|
|
g.Dispose();
|
|
|
|
return bmp;
|
|
|
|
}
|
|
|
|
public static List<RectF> OpenCVRect2Local(List<RectI> rects)
|
|
{
|
|
List<RectF> ret = new List<RectF>();
|
|
|
|
if ((rects != null) && (rects.Count > 0))
|
|
{
|
|
for (int i = 0; i < rects.Count; ++i)
|
|
{
|
|
RectI rect = rects[i];
|
|
RectF rectF = new RectF();
|
|
rectF.X = (double)rect.X / IR_SCALED_WIDTH;
|
|
rectF.Width = (double)rect.Width / IR_SCALED_WIDTH;
|
|
rectF.Y = (double)(IR_SCALED_HEIGHT + CAMERAS_OFFSET_Y - rect.Y- rect.Height) / IR_SCALED_HEIGHT;
|
|
rectF.Height = (double)rect.Height / IR_SCALED_HEIGHT;
|
|
ret.Add(rectF);
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
public static int getDefaultX()
|
|
{
|
|
int value = CAMERAS_OFFSET_X;
|
|
try
|
|
{
|
|
Settings settings = new Settings();
|
|
value = settings.defaultX;
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
}
|
|
return value;
|
|
}
|
|
public static int getDefaultY()
|
|
{
|
|
int value = CAMERAS_OFFSET_Y;
|
|
try
|
|
{
|
|
Settings settings = new Settings();
|
|
value = settings.defaultY;
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public static void setDefaultX(int value)
|
|
{
|
|
try
|
|
{
|
|
Settings settings = new Settings();
|
|
settings.defaultX = value;
|
|
settings.Save();
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
}
|
|
}
|
|
public static void setDefaultY(int value)
|
|
{
|
|
try
|
|
{
|
|
Settings settings = new Settings();
|
|
settings.defaultY = value;
|
|
settings.Save();
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public static void setOffset(int x, int y)
|
|
{
|
|
CAMERAS_OFFSET_X = x;
|
|
CAMERAS_OFFSET_Y = y;
|
|
}
|
|
public static int getOffsetX()
|
|
{
|
|
return CAMERAS_OFFSET_X;
|
|
}
|
|
public static int getOffsetY()
|
|
{
|
|
return CAMERAS_OFFSET_Y;
|
|
}
|
|
public static int adjustX(int adj)
|
|
{
|
|
CAMERAS_OFFSET_X += adj;
|
|
return CAMERAS_OFFSET_X;
|
|
}
|
|
public static int adjustY(int adj)
|
|
{
|
|
CAMERAS_OFFSET_Y += adj;
|
|
return CAMERAS_OFFSET_Y;
|
|
}
|
|
} |