当前位置:网站首页>C # +opencvsharp+wpf learning notes (I)
C # +opencvsharp+wpf learning notes (I)
2022-07-24 09:47:00 【Silent clouds】
opencv Of mat Format conversion bitmap Re turn bitmapimage
utilize opencvSharp Import image
One 、 Class libraries that need to be referenced
using OpenCvSharp;
using System.Drawing;
using System.IO;
Two 、 utilize opencv Open the picture
Mat img = new Mat(@"F:\lena.png", ImreadModes.Grayscale);
//Grayscale Is to introduce gray image , In addition, it can also be the original color image
// there Mat Namely opencv Processed image format ,@ Followed by the path of the file , Change your path
// Then you can use it directly imshow Show , But here we are going to use wpf Of image Control display
3、 ... and 、Mat Format conversion Bitmap Bitmap
opencv There is a built-in function that can put Mat To Bitmap.
public Bitmap MatToBitmap(Mat img)
{
return OpenCvSharp.Extensions.BitmapConverter.ToBitmap(img);
}
Four 、Bitmap turn BitmapImage
because wpf Of image Control can only display BitmapImage Type of picture , So turn to Bitmap after , You have to continue to convert to BitmapImage.
For processing a single picture , Just use the following method . But if there are multiple pictures , This will take up a lot of memory .
For details, please refer to the link : https://blog.csdn.net/chuangand/article/details/48031271.
public BitmapImage bitmapToimage(Bitmap bitimg)
{
using (MemoryStream stream = new MemoryStream())
{
bitimg.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Position = 0;
BitmapImage result = new BitmapImage();
result.BeginInit();
result.CacheOption = BitmapCacheOption.OnLoad;
result.StreamSource = stream;
result.EndInit();
result.Freeze();
return result;
}
}
5、 ... and 、 stay wpf Of Image Control to display a picture
Click event function of Edit button , Make the picture appear on it .
Mat img = new Mat(@"F:\lena.png", ImreadModes.Grayscale);
Bitmap bitmap = MatToBitmap(img);
BitmapImage bitmapimg = bitmapToimage(bitmap);
imgshow.Source = bitmapimg;
边栏推荐
- Raspberry Pie: serial port login does not display print information
- Basic knowledge of PHP - complete collection of PHP functions
- Countdownlatch and join [concurrent programming]
- Cloud primordial (12) | introduction to kubernetes foundation of kubernetes chapter
- A null pointer exception is reported when the wrapper class inserts into the empty field of the database table
- What does CRM mean? Three "key points" for CRM management software selection
- Gin framework uses session and redis to realize distributed session & Gorm operation mysql
- Aruba learning notes 06 wireless control AC basic configuration (CLI)
- [don't bother to strengthen learning] video notes (II) 2. Write a small example of Q learning
- CUDA day 2: GPU core and Sm core components [easy to understand]
猜你喜欢

Will your NFT disappear? Dfinity provides the best solution for NFT storage

【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)

Spark Learning: Spark implementation of distcp

2022 trusted cloud authoritative assessment released: Tianyi cloud has obtained ten certifications and five best practices
![[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)](/img/dd/d29a5be7306580ad388ba6487d230f.png)
[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)

Spark Learning: implement compact table command
![[don't bother with reinforcement learning] video notes (I) 1. What is reinforcement learning?](/img/84/48a6a83192a12dafd88bcd74db0955.gif)
[don't bother with reinforcement learning] video notes (I) 1. What is reinforcement learning?

JS locate Daquan to get the brother, parent and child elements of the node, including robot instances
![Raspberry Pie: [failed] failed to start /etc/rc local Compatibility.](/img/c3/d648cea4e8eef20a221dc034ecfc1d.png)
Raspberry Pie: [failed] failed to start /etc/rc local Compatibility.

Tang Yudi opencv background modeling
随机推荐
JS locate Daquan to get the brother, parent and child elements of the node, including robot instances
The most complete solution for distributed transactions
DSP development, using CCS software to establish engineering and burning
PHP debugging tool - socketlog installation and usage
PHP Basics - session control - cookies
Vector control of permanent magnet synchronous motor (I) -- mathematical model
详解LinkedList
CUDA day 2: GPU core and Sm core components [easy to understand]
力扣300-最长递增子序列——动态规划
A null pointer exception is reported when the wrapper class inserts into the empty field of the database table
Synchronized scope "concurrent programming"
Little dolphin "transformed" into a new intelligent scheduling engine, which can be explained in simple terms in the practical development and application of DDS
What is the cloud native mid platform business architecture?
Li Kou 300 longest increasing subsequence dynamic programming
It's eleven again. Those jokes about nagging programmers going home for blind dates
Map processing background management menu data
Spark Learning: how to choose different association forms and mechanisms?
PHP debugging tool - how to install and use firephp
[Luogu p3426] SZA template (string) (KMP)
MySQL query database capacity size