当前位置:网站首页>C#_ Convert camera images to bitmap format and draw Crosshairs
C#_ Convert camera images to bitmap format and draw Crosshairs
2022-06-29 20:20:00 【Impossible_ Received_ Rubbish】
Before MFC Yes, it is OpenCV How to draw a line and then display it to the control ,C# Next use OpenCV Haven't studied , But refer to converting the image into Bitmap Format and then draw lines can also be achieved
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using DVPCameraType;// The camera SDK Namespace
namespace DrawCross
{
public partial class Form1 : Form
{
public static IntPtr m_ptr_wnd = new IntPtr();
public static IntPtr m_ptr = new IntPtr();
private DVPCamera.dvpStreamCallback _proc;
uint m_handle = 0;// Camera handle
public static bool m_draw=false;
public static Form1 lpsf;//Bitmap Map handle
public Form1()
{
InitializeComponent();
m_ptr_wnd = pictureBox1.Handle;// Map control handle
lpsf = this;
Select.Items.Clear();// Clear the list each time you click the enumerate button
int item;// Drop down list item index
uint count = 0;// Number of equipment
dvpCameraInfo dev_info = new dvpCameraInfo();// Camera information structure
DVPCamera.dvpRefresh(ref count);// Refresh the number of cameras
for (uint i = 0; i < count; i++)
{
DVPCamera.dvpEnum(i, ref dev_info);// enumeration
item = Select.Items.Add(dev_info.FriendlyName);// Add to drop-down list , Returns the 0
Select.SelectedIndex = item;// Set the drop-down list item as the first index
}
}
//private ColorPalette tempPalette;
/* Video stream callback function */
public static int _dvpStreamCallback(uint handle, dvpStreamEvent _event, IntPtr pContext, ref dvpFrame refFrame, IntPtr pBuffer)
{
if(m_draw)
{
/* Draw crosshairs */
// transformation BMP Bitmap
Bitmap bmp = null;
if (refFrame.format == dvpImageFormat.FORMAT_BGR24)
{
bmp = new Bitmap(refFrame.iWidth, refFrame.iHeight, refFrame.iWidth * 3, PixelFormat.Format24bppRgb, pBuffer);
}
else if (refFrame.format == dvpImageFormat.FORMAT_MONO)
{
ColorPalette tempPalette;
bmp = new Bitmap(refFrame.iWidth, refFrame.iHeight, refFrame.iWidth, PixelFormat.Format8bppIndexed, pBuffer);
tempPalette = bmp.Palette;
for (int i = 0; i < 255; i++)
{
tempPalette.Entries[i] = System.Drawing.Color.FromArgb(0, i, i, i);
}
bmp.Palette = tempPalette;
}
//bmp.Save("D:\\" + count++ + ".jpeg", ImageFormat.Jpeg);
//return 0;
#region
Bitmap rgb = new Bitmap(refFrame.iWidth, refFrame.iHeight);
Graphics g = Graphics.FromImage(bmp);
Pen mypen = new Pen(Color.Red, 4);
Brush nBrush = new SolidBrush(Color.Blue);
int a;
Font font = new Font(" Microsoft YaHei ", 56);
g.DrawImage(bmp, 0, 0, refFrame.iWidth, refFrame.iHeight);
a = refFrame.iHeight / 2;
g.DrawLine(mypen, 0, a, refFrame.iWidth, a);
a = refFrame.iWidth / 2;
g.DrawLine(mypen, a, 0, a, refFrame.iHeight);
//g.DrawString("DuShen", font, nBrush, refFrame.iWidth / 2, refFrame.iHeight / 2);
lpsf.pictureBox1.Image = bmp;
#endregion
}
else
{
// Paint image data to the map control
dvpStatus status = DVPCamera.dvpDrawPicture(ref refFrame, pBuffer, m_ptr_wnd, (IntPtr)0, (IntPtr)0);
}
return 0;
}
private void Refresh_Click(object sender, EventArgs e)
{
Select.Items.Clear();// Clear the list each time you click the enumerate button
int item;// Drop down list item index
uint count = 0;// Number of equipment
dvpCameraInfo dev_info = new dvpCameraInfo();// Camera information structure
DVPCamera.dvpRefresh(ref count);// Refresh the number of cameras
for (uint i = 0; i < count; i++)
{
DVPCamera.dvpEnum(i, ref dev_info);// enumeration
item = Select.Items.Add(dev_info.FriendlyName);// Add to drop-down list , Returns the 0
Select.SelectedIndex = item;// Set the drop-down list item as the first index
}
}
private void Open_Click(object sender, EventArgs e)
{
DVPCamera.dvpOpenByName(Select.Text, dvpOpenMode.OPEN_NORMAL, ref m_handle);// open
// Register the video stream callback function
_proc = _dvpStreamCallback;
DVPCamera.dvpRegisterStreamCallback(m_handle, _proc, dvpStreamEvent.STREAM_EVENT_PROCESSED, m_ptr);
DVPCamera.dvpSetTargetFormat(m_handle, dvpStreamFormat.S_BGR24);
dvpStatus status = DVPCamera.dvpStart(m_handle);// Start the video stream
}
private void Set_Click(object sender, EventArgs e)
{
DVPCamera.dvpShowPropertyModalDialog(m_handle, this.Handle);// Parameter setting window
}
private void DrawCross_CheckedChanged(object sender, EventArgs e)
{
if(DrawCross.Checked)
{
m_draw = true;
}
else
{
m_draw = false;
}
}
}
}

边栏推荐
- I found another cross domain method by chance. I don't know if anyone has ever played this way
- data link layer
- Three.js开发:粗线的画法
- How to use filters in jfinal to monitor Druid for SQL execution?
- 偶然发现了另一种跨域方式,不知道有没有人这么玩过
- Mysql Json 数据类型&函数
- Website stress testing tool - webbench
- Ovirt database modify delete node
- A keepalived high availability accident made me learn it again!
- mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
猜你喜欢
随机推荐
2021 CCPC Harbin E. power and modulo (thinking questions)
Bigder:自动化测试工程师
通过MeterSphere和DataEase实现项目Bug处理进展实时跟进
2022年深圳市福田区支持先进制造业发展若干措施
【译】十二因子应用(四)
Defense cornerstone in attack and defense drill -- all-round monitoring
Sword finger offer 59 - I. maximum value of sliding window
Fastadmin background setting radio button
freemarker模板框架生成图片
Following the crowd hurts you
[buuctf.reverse] 142_[SUCTF2019]babyunic
软件工程—原理、方法与应用
Liunx instruction
Flume-ng配置
thinkphp5中的配置如何使用
0/1 score planning topic
PHP implementation extracts non repeated integers (programming topics can be the fastest familiar functions)
How to solve the problem of insufficient memory space in Apple iPhone upgrade system?
0/1分数规划专题
[notes] take notes again -- learn by doing Verilog HDL – 008
![[compilation principle] syntax analysis](/img/9e/6b1f15e3da9997b08d11c6f091ed0e.png)








