//下面的函数实现物体提取的操作
BOOL DIB:: CompareImg2(HANDLE hDIBBK,HANDLE hDIBCurrent,CPoint pt1,CPoint pt2)
{
if(abs(pt1.x-pt2.x)>3 || abs(pt1.y -pt2.y)>3)
{
AfxMessageBox("Imgs Offset are too big");
return false;
}
LPBITMAPINFOHEADER lpbi1,lpbi2;
lpbi1 = (LPBITMAPINFOHEADER)GlobalLock(hDIBBK);
int width1 = lpbi1->biWidth;
int height1 = lpbi1->biHeight;
lpbi2 = (LPBITMAPINFOHEADER)GlobalLock(hDIBCurrent);
int width2 = lpbi2->biWidth;
int height2 = lpbi2->biHeight;
if(width1 != width2 || height1 != height2)
{
GlobalUnlock(hDIBBK);
GlobalUnlock(hDIBCurrent);
AfxMessageBox("Img is not same size");
return false;
}
LPBYTE lpData1,lpData2;
lpData1 = this->FindDIBBits(hDIBBK);
lpData2 = this->FindDIBBits(hDIBCurrent);
WORD wBytesPerLine = this->BytePerLine(hDIBBK);
int xleft,xright,ytop,ybottom;
if(pt1.x>=pt2.x)
{
xleft = pt2.x;
xright =width1-pt1.x-1;
}
else
{
xleft = pt1.x;
xright = width1-pt2.x-1;
}
if(pt1.y >=pt2.y)
{
ytop = pt2.y;
ybottom = height1-pt1.y-1;
}
else
{
ytop = pt1.y;
ybottom = height1-pt2.y-1;
}
long sum=0;
long lOffset;
for(int i=-ytop;i<=ybottom;i++)
for(int j=-xleft;j<=xright;j++)
{
lOffset = this->PixelOffset(i+pt1.y,j+pt1.x,wBytesPerLine);
int c11 = *(lpData1+lOffset++);
int c12 = *(lpData1+lOffset++);
int c13 = *(lpData1+lOffset++);
lOffset = this->PixelOffset(i+pt2.y,j+pt2.x,wBytesPerLine);
int c21 = *(lpData2+lOffset++);
int c22 = *(lpData2+lOffset++);
int c23 = *(lpData2+lOffset++);
lOffset = this->PixelOffset(i+pt2.y,j+pt2.x,wBytesPerLine);
*(lpData2+lOffset++) = abs(c11-c21);
*(lpData2+lOffset++) = abs(c12-c22);
*(lpData2+lOffset++) = abs(c13-c23);
}
for(i =0;i<height1;i++)
for(int j=0;j<width1;j++)
{
if(i<pt2.y-ytop || i>pt2.y+ybottom||j<pt2.x-xleft || j >pt2.x+xright)
{
lOffset = this->PixelOffset(i,j,wBytesPerLine);
*(lpData2+lOffset++) = 0;
*(lpData2+lOffset++) = 0;
*(lpData2+lOffset++) = 0;
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>