ColorMatrix를 사용하여 다른 솔루션을.
ImageAttributes.SetColorMatrix를 수정하여 이미지 색상을 변경할 수 있습니다.
임계 값을 조정하여 밝기를 미세 조정합니다. 1.
로 설정하면
ImageAttributes.SetThreshold
설정하면 0으로 촬영 된 이미지는 또한 "반전"원본 비트 맵의 색상 패턴에 의존한다는 생각 때문에 다른 접근을 시도, 모두 흰색 반대입니다 . 때때로 픽셀의 밝기를 반전시키지 않으면 더 나은 해결책을 얻을 수 있습니다.
OCR은 어떤 값이 더 적합한 지 확인하려면 "훈련"해야합니다. 에 R = 레드 G = 녹색 B = 블루 A = 알파 채널 W = 흰색 (밝기)
수정 밝기 구성 요소 :
Recoloring (MSDN)
ASCII Art Generator (CodeProject)
밝기 매트릭스 :
다음에서보세요 파일에서 이미지를 가져 오기에 "반전"
R G B A W
R [1 0 0 0 0]
G [0 1 0 0 0]
B [0 0 1 0 0]
A [0 0 0 1 0]
W [b b b 0 1] <= Brightness
를 얻을
,691,363,210
string _path = @"Image Path";
FileStream _fs = new FileStream(_path, FileMode.Open, FileAccess.Read);
Image _img = new Bitmap(_fs);
또는 클립 보드
Image _img = Clipboard.GetImage();
은 이와 같이 그래픽 콘텍스트를 생성하는 한계가 있다고해야한다. 이미지가 B & W 인 경우
using System.Drawing;
using System.Drawing.Imaging;
var BW_Inverted_matrix = new float[][]
{
new float[] { -1, -1, -1, 0, 0},
new float[] { -1, -1, -1, 0, 0},
new float[] { -1, -1, -1, 0, 0},
new float[] { 0, 0, 0, 1, 0},
new float[] { 1.5f, 1.5f, 1.5f, 0, 1} //Adjusted: to combine with threshold
};
var BW_matrix = new float[][]
{
new float[] { 1, 1, 1, 0, 0},
new float[] { 1, 1, 1, 0, 0},
new float[] { 1, 1, 1, 0, 0},
new float[] { 0, 0, 0, 1, 0},
new float[] {-1, -1, -1, 0, 1}
};
using (Graphics gr = Graphics.FromImage(_img))
{
// Adjust the threshold as needed
float _threshold = 0.2f;
ImageAttributes _ImageAttributes = new ImageAttributes();
_ImageAttributes.SetColorMatrix(new ColorMatrix(BW_Inverted_matrix));
_ImageAttributes.SetThreshold(_threshold);
Rectangle _rect = new Rectangle(0, 0, _img.Width, _img.Height);
gr.DrawImage(_img, _rect, 0, 0, _img.Width, _img.Height, GraphicsUnit.Pixel, _ImageAttributes);
}
이 경우
OpenCV의 약간 과잉 될 수 있습니다 들어오는 이미지 그대로 문자 그대로 흑백이나 그레이 또는 기타 (미묘한) 색상이 포함될 수 있습니까? 그렇다면 어떻게 처리할까요? –
이 흑백 이미지입니까? –
어, 나는 이미지가 순수한 흑백이라고 의심합니다. 그 이유는 컬러 중 하나를 교체하면 빈 이미지가 생성되기 때문입니다. – Nyerguds