标题:如何去除JPG图片中红章,有对_Gdiplus.vcx有研究的吗?
只看楼主
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
结帖率:76.47%
已结贴  问题点数:20 回复次数:11 
如何去除JPG图片中红章,有对_Gdiplus.vcx有研究的吗?
如题,OCR识别,红章(红色字符,线条)碍事,需要去除。请教解决办法!谢谢!

有个思路:取到所有红色像素,然后清理掉(白色填充)……

[此贴子已经被作者于2020-7-3 09:25编辑过]

搜索更多相关主题的帖子: 图片 像素 研究 填充 JPG 
2020-07-02 18:41
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:20 
不明真相
2020-07-03 11:14
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
得分:0 
以下是引用吹水佬在2020-7-3 11:14:12的发言:

不明真相

就是有张发票进行OCR识别,但是备注栏通常会有红章,会影响识别结果,因此去掉红色,会提供识别率。

谢谢大佬关注
2020-07-03 15:07
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
去色相对简单点,补色怎算?
2020-07-03 16:47
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
得分:0 
以下是引用吹水佬在2020-7-3 16:47:33的发言:

去色相对简单点,补色怎算?


用白色填充!
2020-07-03 16:49
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用radiofan在2020-7-3 16:49:05的发言:



用白色填充!

那就用白色替换红色
给个示图看看
2020-07-03 17:11
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
得分:0 
以下是引用吹水佬在2020-7-3 17:11:31的发言:


那就用白色替换红色
给个示图看看



谢谢!
2020-07-03 20:36
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
给个参考代码,时间问题,像素色的判断就自己去测试
DECLARE LONG GdiplusStartup IN gdiplus LONG@, STRING@, LONG
DECLARE LONG GdiplusShutdown IN gdiplus LONG
DECLARE LONG GdipLoadImageFromFile IN gdiplus STRING@, LONG@
DECLARE LONG GdipGetImageWidth IN gdiplus LONG, LONG@
DECLARE LONG GdipGetImageHeight IN gdiplus LONG, LONG@
DECLARE LONG GdipBitmapGetPixel IN gdiplus LONG, LONG, LONG, LONG@
DECLARE LONG GdipBitmapSetPixel IN gdiplus LONG, LONG, LONG, LONG
DECLARE LONG GdipSaveImageToFile IN gdiplus LONG, STRING@, STRING@, LONG
DECLARE LONG GdipDisposeImage IN gdiplus LONG
inFile = "test0.jpg"
outFile = "test1.jpg"
stGSI = 0h01000000000000000000000000000000
pGDI = 0
GdiplusStartup(@pGDI, @stGSI, 0)
pImage = 0
GdipLoadImageFromFile(STRCONV(inFile+0h00,5), @pImage)
nWidth = 0
GdipGetImageWidth(pImage, @nWidth)
nHeight = 0
GdipGetImageHeight(pImage, @nHeight)
nARGB = 0
FOR i=0 TO nWidth-1
    FOR j=0 TO nHeight-1
        GdipBitmapGetPixel(pImage, i, j, @nARGB) && 取像素颜色
        R = BITAND(BITRSHIFT(nARGB,16), 0xFF)
        G = BITAND(BITRSHIFT(nARGB, 8), 0xFF)
        B = BITAND(nARGB, 0xFF)
        IF (在这判断符合条件的R、G、B值)
            nRGB = 要替换的颜色值
            GdipBitmapSetPixel(pImage, i, j, nRGB) && 替换像素颜色
        ENDIF
    ENDFOR
ENDFOR
CLSID_JPG = 0h01F47C55041AD3119A730000F81EF32E
GdipSaveImageToFile(pImage, STRCONV(outFile+0h00,5), CLSID_JPG, 0)
GdipDisposeImage(pImage)
GdiplusShutdown(pGDI)
CLEAR ALL
RETURN

[此贴子已经被作者于2020-7-4 11:51编辑过]

2020-07-04 11:49
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
得分:0 
以下是引用吹水佬在2020-7-4 11:49:47的发言:

给个参考代码,时间问题,像素色的判断就自己去测试
DECLARE LONG GdiplusStartup IN gdiplus LONG@, STRING@, LONG
DECLARE LONG GdiplusShutdown IN gdiplus LONG
DECLARE LONG GdipLoadImageFromFile IN gdiplus STRING@, LONG@
DECLARE LONG GdipGetImageWidth IN gdiplus LONG, LONG@
DECLARE LONG GdipGetImageHeight IN gdiplus LONG, LONG@
DECLARE LONG GdipBitmapGetPixel IN gdiplus LONG, LONG, LONG, LONG@
DECLARE LONG GdipBitmapSetPixel IN gdiplus LONG, LONG, LONG, LONG
DECLARE LONG GdipSaveImageToFile IN gdiplus LONG, STRING@, STRING@, LONG
DECLARE LONG GdipDisposeImage IN gdiplus LONG
inFile = "test0.jpg"
outFile = "test1.jpg"
stGSI = 0h01000000000000000000000000000000
pGDI = 0
GdiplusStartup(@pGDI, @stGSI, 0)
pImage = 0
GdipLoadImageFromFile(STRCONV(inFile+0h00,5), @pImage)
nWidth = 0
GdipGetImageWidth(pImage, @nWidth)
nHeight = 0
GdipGetImageHeight(pImage, @nHeight)
nARGB = 0
FOR i=0 TO nWidth-1
    FOR j=0 TO nHeight-1
        GdipBitmapGetPixel(pImage, i, j, @nARGB) && 取像素颜色
        R = BITAND(BITRSHIFT(nARGB,16), 0xFF)
        G = BITAND(BITRSHIFT(nARGB, 8), 0xFF)
        B = BITAND(nARGB, 0xFF)
        IF (在这判断符合条件的R、G、B值)
            nRGB = 要替换的颜色值
            GdipBitmapSetPixel(pImage, i, j, nRGB) && 替换像素颜色
        ENDIF
    ENDFOR
ENDFOR
CLSID_JPG = 0h01F47C55041AD3119A730000F81EF32E
GdipSaveImageToFile(pImage, STRCONV(outFile+0h00,5), CLSID_JPG, 0)
GdipDisposeImage(pImage)
GdiplusShutdown(pGDI)
CLEAR ALL
RETURN


谢谢!我抽空测试下。对这个没有概念,需要从头学!





有点成果

[此贴子已经被作者于2020-7-4 22:13编辑过]

2020-07-04 14:15
antony521
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:168
专家分:161
注 册:2009-8-20
得分:0 
回复 5楼 radiofan
用透明才对
2020-07-04 16:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-502369-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.079756 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved