当前位置:网站首页>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;
边栏推荐
- Lung CT segmentation challenge 2017 dataset download and description
- Re6: reading paper licin: a heterogeneous graph based approach for automatic legal stat identification fro
- Common evaluation indexes of medical image segmentation
- Implementation principle of acid in MySQL
- Leetcode question brushing series -- 174. Dungeon games
- Where is the bitbucket clone address
- 【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)
- At the moment of the epidemic, we need to work harder, aoligui
- Raspberry Pie: the serial port has been unable to read the information sent by the upper computer
- Learn more about the synchronized lock upgrade process [concurrent programming]
猜你喜欢

Cloud primordial (12) | introduction to kubernetes foundation of kubernetes chapter

An article takes you to understand the operation of C language files in simple terms

Gnuplot software learning notes
![[don't bother to strengthen learning] video notes (II) 1. What is Q-learning?](/img/4f/809adc96e30fad03a113acc3df4b61.png)
[don't bother to strengthen learning] video notes (II) 1. What is Q-learning?

Spark Learning: how to choose different association forms and mechanisms?

Compilation and linking of programs

Raspberry Pie: /bin/sh: 1: bison: not found
![[don't bother to strengthen learning] video notes (IV) 1. What is dqn?](/img/74/51219a19595f93e7a85449f54d354d.png)
[don't bother to strengthen learning] video notes (IV) 1. What is dqn?

Add SSH key to bitbucket

Opencv learning Day5
随机推荐
OPENCV学习DAY5
Where is the bitbucket clone address
Makefile variables and dynamic library static library
What is the cloud native mid platform business architecture?
缓冲区的概念真的理解么?带你揭开缓冲区的面纱~
Countdownlatch and join [concurrent programming]
NVIDIA set persistent mode
PHP log base - monolog knowledge collation
力扣300-最长递增子序列——动态规划
PHP Basics - PHP types
Learn more about the synchronized lock upgrade process [concurrent programming]
Getting started with sorting - insert sorting and Hill sorting
Vector control of permanent magnet synchronous motor (I) -- mathematical model
Code random notes_ Linked list_ Turn over the linked list in groups of 25K
Scheme and software analysis of dual computer hot standby system "suggestions collection"
Re6: reading paper licin: a heterogeneous graph based approach for automatic legal stat identification fro
Spark Learning: Spark implementation of distcp
String sort
Makefile变量及动态库静态库
Detailed LinkedList