58、Visual studio 2019+C#传递Mat数据给C++动态包处理,并将处理结果Mat返回给C#显示、保存_sxj731533730-CSDN博客
二、然后在创建.NET工程,拖拽三个按钮和两个pictureBox画布
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using OpenCvSharp;
using System.Drawing;
using OpenCvSharp.Extensions;
using System.Text;
namespace WindowsFormsApp1
{
static class Program
{
[DllImport(@"F:\sxj\20211108\detectYolov5Ncnn\x64\Release\detectYolov5Ncnn.dll",
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall)]
public static extern int init_model(StringBuilder model_param, StringBuilder model_bin);
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
StringBuilder model_param = new StringBuilder("F:\\sxj\\20211201\\yolov5s_6.0.param");
StringBuilder model_bin = new StringBuilder("F:\\sxj\\20211201\\yolov5s_6.0.bin");
init_model(model_param, model_bin);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;
using System.Runtime.InteropServices;
using OpenCvSharp.Extensions;
using System.IO.Compression;
using System.Drawing.Imaging;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
[DllImport(@"F:\sxj\20211108\detectYolov5Ncnn\x64\Release\detectYolov5Ncnn.dll")]
public static extern int detect_image(byte[] ImageBuffer, byte[] ImageResult, int imageWidth, int imageHeight);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = @"jpeg|*.jpg|bmp|*.bmp|gif|*.gif";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string fullpath = openFileDialog.FileName;
FileStream fs = new FileStream(fullpath, FileMode.Open);
byte[] picturebytes = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
picturebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
MemoryStream ms = new MemoryStream(picturebytes);
Bitmap bmpt = new Bitmap(ms);
pictureBox1.Image = bmpt;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
else {
MessageBox.Show("图片打开失败");
}
}
private void button2_Click(object sender, EventArgs e)
{
SaveFileDialog saveImageDialog = new SaveFileDialog();
saveImageDialog.Title = "图片保存";
saveImageDialog.Filter = @"jpeg|*.jpg|bmp|*.bmp";
saveImageDialog.FileName = System.DateTime.Now.ToString("yyyyMMddHHmmss");//设置默认文件名
if (saveImageDialog.ShowDialog() == DialogResult.OK)
{
string fileName = saveImageDialog.FileName.ToString();
//Console.WriteLine("fileName" + fileName);
if (fileName != "" && fileName != null)
{
string fileExtName = fileName.Substring(fileName.LastIndexOf(".") + 1).ToString();
//Console.WriteLine("fileExtName" + fileExtName);
System.Drawing.Imaging.ImageFormat imgformat = null;
if (fileExtName != "")
{
switch (fileExtName)
{
case "jpg":
imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case "bmp":
imgformat = System.Drawing.Imaging.ImageFormat.Bmp;
break;
default:
imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
}
try
{
Bitmap bit = new Bitmap(pictureBox2.Image);
MessageBox.Show(fileName);
pictureBox2.Image.Save(fileName, imgformat);
}
catch
{
}
}
}
}
}
private void button3_Click(object sender, EventArgs e)
{
Bitmap bmp = (Bitmap)pictureBox1.Image.Clone();
byte[] source = GetBGRValues(bmp);
byte[] dest = source;
detect_image(source, dest, bmp.Width, bmp.Height);
Bitmap bmpConvert = Byte2Bitmap(dest, bmp.Width, bmp.Height);
Image images = bmpConvert;
pictureBox2.Image = images;
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
}
public static byte[] GetBGRValues(Bitmap bmp)
{
var rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
var bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat);
var rowBytes = bmpData.Width * Image.GetPixelFormatSize(bmp.PixelFormat) / 8;
var imgBytes = bmp.Height * rowBytes;
byte[] rgbValues = new byte[imgBytes];
IntPtr ptr = bmpData.Scan0;
for (var i = 0; i < bmp.Height; i++)
{
Marshal.Copy(ptr, rgbValues, i * rowBytes, rowBytes);
ptr += bmpData.Stride;
}
bmp.UnlockBits(bmpData);
return rgbValues;
}
public static Bitmap Byte2Bitmap(Byte[] data, int width, int height)
{
Bitmap image = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
BitmapData bmData = image.LockBits(rect, ImageLockMode.ReadWrite, image.PixelFormat);
IntPtr ptr = bmData.Scan0;
for (int i = 0; i < image.Height; i++)
{
Marshal.Copy(data, i * image.Width * 3, ptr, image.Width * 3);
ptr = (IntPtr)(ptr.ToInt64() + bmData.Stride);
}
image.UnlockBits(bmData);
return image;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
分页显示一直是web开发中一大烦琐的难题,传统的网页设计只在一个JSP或者ASP页面中书写所有关于数据库操作的代码,那样做分页可能简单一点,但当把网站分层开发后,分页就比较困难了,下面是我做Spring+Hibernate+Struts2项目时设计的分页代码,与大家分享交流。
1、DAO层接口的设计,在MemberDao接口中定义了如下两个方法:
public in
/*
*使用对象类型
*/
--建立和使用简单对象类型
--对象类型包括对象类型规范和对象类型体两部分。
--建立和使用不包含任何方法的对象类型
CREATE OR REPLACE TYPE person_typ1 as OBJECT(
name varchar2(10),gender varchar2(4),birthdate date
);
drop type p
what 什么
your 你
name 名字
my 我的
am 是
one 一
two 二
three 三
four 四
five 五
class 班级,课
six 六
seven 七
eight 八
nince 九
ten 十
zero 零
how 怎样
old 老的
eleven 十一
twelve 十二
thirteen
spring security 3中推荐使用BCrypt算法加密密码了,以前使用的是md5,
Md5PasswordEncoder 和 ShaPasswordEncoder,现在不推荐了,推荐用bcrpt
Bcrpt中的salt可以是随机的,比如:
int i = 0;
while (i < 10) {
String password = "1234
1.前言。
如题。
2.代码
(1)单表查重复数据,根据a分组
SELECT m.a,m.b, INNER JOIN (select a,b,COUNT(*) AS rank FROM test.`A` A GROUP BY a HAVING rank>1 )k ON m.a=k.a
(2)多表查询 ,
使用改为le