当前位置:网站首页>Opencv desaturation
Opencv desaturation
2022-06-13 00:50:00 【Small fish game development】
demo:
Game character recognition , Simple preprocessing
First, prepare a picture for character recognition 
Direct use OCR Recognition will identify a lot of junk information , At this time, we need to preprocess the image 
It can be seen from the color scale above that the left side should be the junk information behind the background board , On the right is the text information we need , Just remove the background information to get the text information to be processed
Desaturate the image before threshold operation
static Mat Preprocessing(string file)
{
var img = Cv2.ImRead(file,ImreadModes.AnyColor);
if (img.Empty())
return null;
Mat result = Mat.Zeros(img.Size(), img.Type());
img.Desaturation(result);
// threshold
Cv2.Threshold(result, result, 100, 255, ThresholdTypes.Binary);
return result;
}
Acquired image , The background looks good after discarding the background information 
Use the desert for this image OCR operation , Fairly good recognition , It is only necessary to limit the recognition range, and the result should be correct , It is very fast when there are few words in the font 
Look at the results of online character recognition , slow 
Baidu API High precision version , It's slow , The Standard Version return is empty my God 
Desaturation
The formula :
Gray = ( Math.max(Red, Green, Blue) + Math.min(Red, Green, Blue) ) / 2
public static class ImageHelper
{
/// <summary>
/// Image desaturation
/// </summary>
/// <param name="src"></param>
/// <param name="dst"></param>
public static unsafe void Desaturation(this Mat src, Mat dst)
{
System.Diagnostics.Debug.Assert(dst != null, "dst not set to an instance of an object.");
System.Diagnostics.Debug.Assert(src.Channels() >= 3, "src.Channels < 3");
System.Diagnostics.Debug.Assert(src.Type() == dst.Type(), "src.Type != des.Type");
System.Diagnostics.Debug.Assert(src.Size() == dst.Size(), "src.Size != des.Size");
int height = src.Rows;
int width = src.Cols;
var channels = src.Channels();
Parallel.For(0, height, i =>
{
var ptr = (byte*)src.Ptr(i).ToPointer();
var dstPtr = (byte*)dst.Ptr(i).ToPointer();
for (var j = 0; j < width; j++)
{
var ptrOffset = j * channels;
var max = Math.Max(Math.Max(ptr[ptrOffset], ptr[ptrOffset + 1]), ptr[ptrOffset + 2]);
var min = Math.Min(Math.Min(ptr[ptrOffset], ptr[ptrOffset + 1]), ptr[ptrOffset + 2]);
var color = (byte)((max + min) * 0.5f);
dstPtr[ptrOffset] = color;
dstPtr[ptrOffset + 1] = color;
dstPtr[ptrOffset + 2] = color;
}
});
}
}
边栏推荐
- [error] invalid use of incomplete type uses an undefined type
- 今日在家休息
- Kali system -- host, dig, dnsenum, imtry for DNS collection and analysis
- Cve-2021-24078 vulnerability analysis
- Kotlin collaboration, the life cycle of a job
- [server data recovery] successful cases of data loss recovery during data migration between storage servers
- Binary tree - right view
- Development notes of Mongoose
- Deep learning model pruning
- Leetcode weekly -- April to May
猜你喜欢

JPA execution failed in scheduled task -executing an update/delete query transactionrequiredexception

MySQL locates the position of the character in the string String substitution

Kali system -- fierce of DNS collection and analysis

(01).NET MAUI实战 建项目
![[JS component] previous queue prompt](/img/79/9839f68b191b0db490e9bccbeaae1d.jpg)
[JS component] previous queue prompt

深度学习每周期的步数多少合适?

AOF持久化

Arduino control tm1637 common positive four digit nixie tube
![Buuctf's babysql[geek challenge 2019]](/img/6c/957e5e09f252210d0b4cf8771d4ade.png)
Buuctf's babysql[geek challenge 2019]
![[imx6ull] video monitoring project (USB camera +ffmepeg)](/img/f9/1a7b68083b52c973336db9044b52c2.jpg)
[imx6ull] video monitoring project (USB camera +ffmepeg)
随机推荐
Four startup modes of kotlin collaboration
[MRCTF2020]Ez_ bypass --BUUCTF
市值破万亿,连续三个月销量破10万,比亚迪会成为最强国产品牌?
Paper reading and sharing
MySQL queries the quantity of each month and the year-on-year and month on month data of each month
DNS attack surface analysis
Kotlin 协程,job的生命周期
Assembly language learning
人神共愤,唐山“群殴女性事件”细节...
从ADK的WinPE自己手动构建自己的PE
Sequence table - find main element
【SCA-CNN 解读】空间与通道注意力:Spatial and Channel-wise Attention
Summary of openstack installation problems
Buuctf babyupload[gxyctf2019]
Card constructions -- two points
Arduino interrupt
Another year 1024, happy programmer's Day!
什么是 dummy change?
阿姨学代码续集:能力吊打大批程序员
Browser console injection JS