简单的图片对比函数
2011-12-06 11:43
337 查看
function Compare(bit1: TBitmap; bit2: TBitmap; nC: Integer; Img: TImage): Integer; var x,y , nRe: Integer; bx, by, bbs: Byte; bColor: TColor; temBit: TBitmap; begin if Img <> nil then begin temBit := TBitmap.Create; temBit.Width := bit1.Width; temBit.Height := bit1.Height; end; nRe := 0; for x := 0 to bit1.Width -1 do begin for y:= 0 to bit1.Height -1 do begin bx := GetBValue(bit1.Canvas.pixels[x,y]); by := GetBValue(bit2.Canvas.pixels[x,y]); bbs := abs(bx- by); if bbs < nC then begin bColor := clBlack; end else begin bColor := clWhite; Inc(nRe); end; if Img <> nil then temBit.Canvas.pixels[x,y]:= bColor; end; end; if Img <> nil then Img.Picture.Bitmap.Assign(temBit); temBit.Free; Result := nRe; end;
//一种更快的方法 function Compare2(bit1: TBitmap; bit2: TBitmap; nC: Integer; Img: TImage): Integer; var x,y , nRe: Integer; bbs: Byte; bColor: TColor; temBit: TBitmap; pix1, pix2: PByteArray; begin if Img <> nil then begin temBit := TBitmap.Create; temBit.Width := bit1.Width; temBit.Height := bit1.Height; end; nRe := 0; for y:= 0 to bit1.Height -1 do begin pix1 := bit1.Scanline[y]; pix2 := bit2.Scanline[y]; for x:= 0 to bit1.Width-1 do begin bbs := abs(pix1[x*3]- pix2[x*3]); if bbs < nC then begin bColor := clBlack; end else begin bColor := clWhite; Inc(nRe); end; if Img <> nil then temBit.Canvas.pixels[x,y]:= bColor; end; end; if Img <> nil then begin Img.Picture.Bitmap.Assign(temBit); temBit.Free; end; Result := nRe; end;
取灰度值, 设置容差, 返回差度
相关文章推荐
- 如何用最简单最快的方法判断一个BMP图片是否为黑白图片?我现在是全图片scanline 然后再加以分析,太慢了,有没有直接的函数可以做到呢?
- 简单的内容差异对比函数
- 原生代码加载网络图片和Volley和Picasso的简单介绍和优缺点对比
- php curl简单采集图片生成base64编码(并附curl函数参数说明)
- 简单的php 验证图片生成函数
- python 下载 保存 图片的urllib.urlretrieve()函数 简单用法
- python2 和 python3 下载网上图片的简单实现和对比
- setInerval()函数的活用,JavaScript构建简单的图片切换程序
- 最简单的加密、解密图片函数和测试用例
- 简单对比C语言中的fputs()函数和fputc()函数
- 简单同步时 EnterCriticalSection/InterlockedIncrement系列函数的对比
- 机器人眼中的图片上是固定的==有物体在上面移动==二张图片的对比即活动识别物==特简单的机器人动态识别技术.
- Lua io.write() 对比 print 函数, 简单 I/O 模式
- 利用LineDDA函数来实现简单的图片移动动画
- 普通情况下的图片懒性加载 简单封装图片预加载函数
- arm汇编的学习笔记,对比x86和arm(1)-从最简单的函数谈起
- 简单的验证图片生成函数
- SQLServer和Oracle的常用函数对比
- 模拟带图片的select简单插件