📄 afloodfill8.cpp
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "CvTest.h"
/* Testing parameters */
static char FuncName[] = "cvFloodFill8";
static char TestName[] = "Flood Fill 8-connected function test";
static char TestClass[] = "Algorithm";
typedef struct
{
int nx0;
ushort nx1;
ushort ny1;
uchar q1;
uchar q2;
uchar unv;
uchar* b;
uchar* I;
} consts;
int Counter8=0;
static int X1=0, X2=0, Y1=0, Y2=0;
/*---------------------- Test function (the most slowly algorithm) ----------------------- */
CvStatus _cvFloodFill8uC1R_slow8 ( uchar* pImage,
int step,
CvSize imgSize,
CvPoint initPoint,
int nv,
int d1,
int d2 )
{
int i, j, k, ij, ijb, ij1, nx, ny, n, nx1, ny1, mNew, ov, nxj, nxjb;
uchar *b = 0, b0, q1, q2, q10, q20;
nx = imgSize.width; ny = imgSize.height;
ij = initPoint.x + nx*initPoint.y;
ov = pImage[ij];
n = nx*ny;
nx1 = nx-1; ny1 = ny-1;
b0=1;
q10=(uchar)d1; q20=(uchar)d2;
if( (b=(uchar*)icvAlloc(n*sizeof(uchar))) == NULL) return CV_OUTOFMEM_ERR;
for(k=0; k<n; k++) b[k]=0;
b[ij]=1;
do
{
mNew = 0;
for(j=0; j<ny; j++)
{
nxj = step*j;
nxjb= nx *j;
for(i=0; i<nx; i++)
{
ij = i + nxj;
ijb= i + nxjb;
if(b[ijb]!=b0)continue;
b[ijb]++;
q1 = (uchar)((pImage[ij]>q10) ? pImage[ij]-q10 : (uchar)0);
q2 = (uchar)(((int)pImage[ij]+(int)q20<255)?pImage[ij]+q20:(uchar)255);
pImage[ij] = (uchar)nv;
Counter8++;
if(X1>i) X1=i; if(X2<i) X2=i; if(Y1>j) Y1=j; if(Y2<j) Y2=j;
/*------------------------- */
ij1=ij-1;
if((i>0) && (!b[ijb-1]) && (pImage[ij1]>=q1) && (pImage[ij1]<=q2))
{
mNew++;
b[ijb-1]++;
}
ij1=ij+1;
if((i<nx1) && (!b[ijb+1]) && (pImage[ij1]>=q1) && (pImage[ij1]<=q2))
{
mNew++;
b[ijb+1]++;
}
ij1=ij-step;
if((j>0) && (!b[ijb-nx]) && (pImage[ij1]>=q1) && (pImage[ij1]<=q2))
{
mNew++;
b[ijb-nx]++;
}
ij1=ij+step;
if((j<ny1) && (!b[ijb+nx]) && (pImage[ij1]>=q1) && (pImage[ij1]<=q2))
{
mNew++;
b[ijb+nx]++;
}
/*------------------------- */
ij1=ij-step-1;
if((i>0)&&(j>0))
if((!b[ijb-nx-1])&&(pImage[ij1]>=q1)&&(pImage[ij1]<=q2))
{
mNew++;
b[ijb-nx-1]++;
}
ij1=ij-step+1;
if((i<nx1)&&(j>0))
if((!b[ijb-nx+1])&&(pImage[ij1]>=q1)&&(pImage[ij1]<=q2))
{
mNew++;
b[ijb-nx+1]++;
}
ij1=ij+step-1;
if((i>0)&&(j<ny1))
if((!b[ijb+nx-1])&&(pImage[ij1]>=q1)&&(pImage[ij1]<=q2))
{
mNew++;
b[ijb+nx-1]++;
}
ij1=ij+step+1;
if((i<nx1)&&(j<ny1))
if((!b[ijb+nx+1])&&(pImage[ij1]>=q1)&&(pImage[ij1]<=q2))
{
mNew++;
b[ijb+nx+1]++;
}
/*------------------------- */
} /* i */
} /* j */
} while(mNew);
icvFree((void**)&b);
return CV_NO_ERR;
} /* _ipcvFloodFill8uC1R_slow8 */
/*--------------------------------------------------------------------------------------*/
CvStatus _cvFloodFill32fC1R_slow8 ( float* pImage,
int step,
CvSize imgSize,
CvPoint initPoint,
float nv,
float d1,
float d2 )
{
int i, j, k, ij, ij1, ijb, nx, ny, n, nx1, ny1, mNew, nxj, nxjb;
float ov, q1, q2;
uchar *b, b0;
step /= 4;
nx = imgSize.width; ny = imgSize.height; n = nx * ny;
ij = initPoint.x + step*initPoint.y;
ov = pImage[ij];
nx1 = nx-1; ny1 = ny-1;
b0=1;
if( (b=(uchar*)icvAlloc(n*sizeof(uchar))) == NULL) return CV_OUTOFMEM_ERR;
for(k=0; k<n; k++) b[k]=0;
ij = initPoint.x + nx*initPoint.y;
b[ij]=b0;
Counter8 = 0;
do
{
mNew = 0;
for(j=0; j<ny; j++)
{
nxj = step*j;
nxjb= nx *j;
for(i=0; i<nx; i++)
{
ij = i + nxj;
ijb= i + nxjb;
if(b[ijb]!=b0)continue;
b[ijb]++;
q1 = pImage[ij] - d1; q2 = pImage[ij] + d2;
pImage[ij] = nv;
Counter8++;
if(X1>i) X1=i; if(X2<i) X2=i; if(Y1>j) Y1=j; if(Y2<j) Y2=j;
/*------------------------- */
ij1=ij-1;
if((i>0) && (!b[ijb-1]) && (pImage[ij1]>=q1) && (pImage[ij1]<=q2))
{
mNew++;
b[ijb-1]++;
}
ij1=ij+1;
if((i<nx1) && (!b[ijb+1]) && (pImage[ij1]>=q1) && (pImage[ij1]<=q2))
{
mNew++;
b[ijb+1]++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -