当前位置:网站首页>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;
}
});
}
}
边栏推荐
- Kali system -- host, dig, dnsenum, imtry for DNS collection and analysis
- Opencv face recognition of ros2 foxy~galactic~humble
- 今日在家休息
- Three column simple Typecho theme lanstar/ Blue Star Typecho theme
- Biological unlocking - Fingerprint entry process
- Hard (magnetic) disk (I)
- What is pytorch? Explain the basic concepts of pytorch
- How to determine whether T is a value type in a generic type or a reference class- How to determine whether T is a value type or reference class in generic?
- 高阶极点对于波形的影响
- 也许尘埃落地,我们才能想清楚互联网的本质
猜你喜欢

Four startup modes of kotlin collaboration

AOF持久化
![[error] invalid use of incomplete type uses an undefined type](/img/8a/7cb5d270cfd8831ddc146687fe4499.png)
[error] invalid use of incomplete type uses an undefined type

Win10 home vs pro vs enterprise vs enterprise LTSC

Kotlin coroutine suspend function suspend keyword

Kalix system - use of information collection gadgets

Aof persistence

Easyexcel read excel simple demo

Map from getting started to performance optimization

Today's sleep quality record 74 points
随机推荐
Learning and Development notes of mongdb
Kotlin coroutine withcontext switch thread
Kotlin collaboration, the life cycle of a job
MySQL locates the position of the character in the string String substitution
[server data recovery] successful cases of data loss recovery during data migration between storage servers
【SCA-CNN 解读】空间与通道注意力:Spatial and Channel-wise Attention
How many rounds of deep learning training? How many iterations?
With a market value of more than trillion yuan and a sales volume of more than 100000 yuan for three consecutive months, will BYD become the strongest domestic brand?
什么是 Meebits?一个简短的解释
Daily buckle exercise - conclusion
Antdpro - protable realizes the linkage effect of two selection boxes
Browser console injection JS
[003] embedded learning: creating project templates - using stm32cubemx
Android Weather
Rest at home today
ImportError: cannot import name &#039; get_ ora_ doc&#039; from partially initialized module
[sca-cnn interpretation] spatial and channel wise attention
Card constructions -- two points
[JS component] floating text
Stack overflow learning summary