Exemple #1
0
int CBlobLabeling::Labeling(IplImage* image, int nThreshold)  // ���̺� �Լ�
{
	if( image->nChannels != 1 ) 	
		return 0;   // �̹����� ����� �ƴҶ� �Լ� ����.

	int nNumber;  // ��ü���� ���� ����
	
	int nWidth	= image->width;   // �̹����� �ʺ�� ���̸� ����
	int nHeight = image->height;
	
	unsigned char* tmpBuf = new unsigned char [nWidth * nHeight];  // �̹����� ���� 1�������� ����ϱ� ���� �����Ҵ�.

	int i,j;

	for(j=0;j<nHeight;j++)      // �̹����� �ʺ�� ���̸�ŭ for�� �ݺ�
	for(i=0;i<nWidth ;i++)
		tmpBuf[j*nWidth+i] = (unsigned char)image->imageData[j*image->widthStep+i];   // �̹��� ������ ���� temp �迭�� ����
	
	InitvPoint(nWidth, nHeight);   // ���̺��� ���� ����Ʈ �ʱ�ȭ

	nNumber = _Labeling(tmpBuf, nWidth, nHeight, nThreshold);  // ���̺�

	DeletevPoint(); // ����Ʈ �޸� ����

	if( nNumber != _DEF_MAX_BLOBS )		m_recBlobs = new CvRect [nNumber]; // ��ü�� ������ �ʱⰪ�� �ƴҶ� ��ü�� ������ŭ �����Ҵ�.

	if( nNumber != _DEF_MAX_BLOBS )		m_intBlobs = new int [nNumber];

	if( nNumber != 0 )	DetectLabelingRegion(nNumber, tmpBuf, nWidth, nHeight);  // ��ü�� ������ 0�̻� �ϰ�� �簢���� �׸������� ��ǥ Ž��.

	for(j=0;j<nHeight;j++)
	for(i=0;i<nWidth ;i++)
		image->imageData[j*image->widthStep+i] = tmpBuf[j*nWidth+i];  // �ӽ� ������ ���� ���� �̹����� ����

	delete tmpBuf;   // temp ���� ����
	return nNumber;  // ��ü ���� ����
}
int CBlobLabeling::Labeling(IplImage* image, int nThreshold)
{
	if( image->nChannels != 1 ) 	return 0;

	int nNumber;
	
	int nWidth	= image->width;
	int nHeight = image->height;
	
	unsigned char* tmpBuf = new unsigned char [nWidth * nHeight];

	int i,j;

	for(j=0;j<nHeight;j++)
	for(i=0;i<nWidth ;i++)
		tmpBuf[j*nWidth+i] = (unsigned char)image->imageData[j*image->widthStep+i];
	
	// 레이블링을 위한 포인트 초기화
	InitvPoint(nWidth, nHeight);

	// 레이블링
	nNumber = _Labeling(tmpBuf, nWidth, nHeight, nThreshold);

	// 포인트 메모리 해제
	DeletevPoint();

	if( nNumber != _DEF_MAX_BLOBS )		m_recBlobs = new CvRect [nNumber];

	if( nNumber != 0 )	DetectLabelingRegion(nNumber, tmpBuf, nWidth, nHeight);

	for(j=0;j<nHeight;j++)
	for(i=0;i<nWidth ;i++)
		image->imageData[j*image->widthStep+i] = tmpBuf[j*nWidth+i];

	delete tmpBuf;
	return nNumber;
}
int CBlobLabeling::Labeling(cv::Mat image, int nThreshold)
{
	if( (&(image))->channels() != 1 ) 	return 0;

	int nNumber;
	
	int nWidth	= (&(image))->cols;
	int nHeight = (&(image))->rows;
	
	unsigned char* tmpBuf = new unsigned char [nWidth * nHeight];

	int i,j;

	for(j=0;j<nHeight;j++)
	for(i=0;i<nWidth ;i++)
		tmpBuf[j*nWidth+i] = (unsigned char)(&(image))->data[j*(&(image))->step1()+i];
	
	// ���̺?�� ���� ����Ʈ �ʱ�ȭ
	InitvPoint(nWidth, nHeight);

	// ���̺?
	nNumber = _Labeling(tmpBuf, nWidth, nHeight, nThreshold);

	// ����Ʈ �޸� ����
	DeletevPoint();

	if( nNumber != _DEF_MAX_BLOBS )		m_recBlobs = new CvRect [nNumber];

	if( nNumber != 0 )	DetectLabelingRegion(nNumber, tmpBuf, nWidth, nHeight);

	for(j=0;j<nHeight;j++)
	for(i=0;i<nWidth ;i++)
		(&(image))->data[j*(&(image))->step1()+i] = tmpBuf[j*nWidth+i];
	
	delete tmpBuf;
	return nNumber;
}