Ejemplo n.º 1
0
void TTransRemain::CheckPosition(	TImage<unsigned char>	&srcImage,
							TImage<unsigned char >	&dstImage,
							vector<RECT>			&rectSet, 
							const	size_t			radius)
{
	TBmpInfo info;
	info.Width	(srcImage.Width());
	info.Height	(srcImage.Height());
	info.AccordMem();
	
	TBmpBoard bmpBoard;
	bmpBoard.SetBmpInfo(info);
	PixelMem *pPixel = bmpBoard.GetPixelBase();
	memcpy(pPixel, dstImage.Base(), dstImage.Width() * dstImage.Height());
	HDC memHDC = bmpBoard.GetMemDC();
	ArcTemple uptemp	= ArcCreator::CreateArc(radius, ArcTemple::eUpArc);
	ArcTemple downTemp	= ArcCreator::CreateArc(radius, ArcTemple::eDownArc);
	TPoint2D<int>	upCentre;
	TPoint2D<int>	downCentre;
	for(size_t i = 0; i < rectSet.size(); ++i)
	{
		long	upSpeciSide		= rectSet[i].top + (rectSet[i].bottom - rectSet[i].top)/3;
		long	downSpeciSide	= rectSet[i].top + (rectSet[i].bottom - rectSet[i].top)*2/3;
		TRect2D<int>	selectUpArea(rectSet[i].left, rectSet[i].top, rectSet[i].right-1, upSpeciSide);
		TRect2D<int>	selectDownArea(rectSet[i].left, downSpeciSide, rectSet[i].right, rectSet[i].bottom);
		GetTopPos(srcImage, selectUpArea, upCentre, uptemp);
		if (!selectUpArea.Within(upCentre.x(), upCentre.y()))
		{
			upCentre = selectUpArea.Center();
		}
		GetTopPos(srcImage, selectDownArea, downCentre, downTemp);
		if (!selectDownArea.Within(downCentre.x(), downCentre.y()))
		{
			downCentre = selectDownArea.Center();
		}
		
		FillDest(dstImage, upCentre, downCentre, memHDC, radius);
	}
	
	memcpy(dstImage.Base(), pPixel, dstImage.Width()* dstImage.Height());
}
Ejemplo n.º 2
0
bool	TTransRemain::RemainCapsule	(	const TAlloc<PixelMem>	&rawImg, 
										const TImgDim			&rawImgDim, 
										TImage<PelGray8>		&remain,
										RemainParam				&remainParam,
										REMAINMODE				remainMode,
										bool					frontLight)
{
	m_mode = remainMode;
	if(rawImgDim.bytesPerPixel == 3)
	{
		TImage<PelRGB24> rgb(rawImg, rawImgDim);
		if(frontLight)	{	TImgProcess::RGBToGray (rgb, m_rawImage);	}
		else			{	TImgProcess::RGBToGray2(rgb, m_rawImage); }
	}
	else
	{
		m_rawImage.SetImage(rawImg.Base(), rawImgDim);
	}
	remain.SetZero();

	try
	{
		
		TImgProcess::BinaryGray(m_rawImage, m_binImage, remainParam.binaryLowThres, remainParam.binaryUpThres);
//		m_sortObserver.ObserverIMG(SortObserver::MAll, m_cvbProfileImg);
				
		IMG minImage = NULL; 
		FilterBoxMin(	m_binIMG,
						remainParam.minBoxWidth,
						remainParam.minBoxWidth, 
						remainParam.minBoxWidth/2, 
						remainParam.minBoxWidth/2, 
						minImage);
		unsigned char	*pImage = NULL;
		PVPAT			VPA		= NULL;
		GetImageVPA	(	minImage, 0, (void**)&pImage, &VPA);
		memcpy		(	m_minBoxImage.Base(), pImage, m_minBoxImage.Width()*m_minBoxImage.Height());
		ReleaseImage(	minImage);
		
		TImgProcess::SobelFilter(	m_rawImage,	m_sobelImage);
		CapsuleProc::ObservedIMG(SortObserver::MEnh, m_sobelIMG);
		TImgProcess::AndGrayImg	(	m_minBoxImage, m_sobelImage, m_andedImage);	

		CapsuleProc::ObservedIMG(SortObserver::MAnd, m_andedIMG);
	}
	catch (...)
	{
		static int count = 0;
		CString txt;
		txt.Format("D:\\\n%d.txt", count);
		count++;
		
		FILE* pFile = NULL;
		fopen_s(&pFile, "D:\\CatchFile.txt", "wb");
		fwrite(txt, sizeof(char), strlen(txt), pFile);
		fclose(pFile);
		return false;
	}
		
	try
	{
		WhiteBlob		(	m_binIMG, m_whiteBlob);	
		vector<RECT> rectSet = GetMouldRect(m_whiteBlob);	
		
		ExcludeEmpty	(	rectSet, remain.Height(), remain.Width());
		
		CheckPosition	(	m_andedImage, remain, rectSet, remainParam.radius);
		TImgProcess::AndGrayImg(m_rawImage, remain, remain);
	}	
	catch (...)
	{
		static int count = 0;
		CString txt;
		txt.Format("D:\\\n%d.txt", count);
		count++;

		FILE* pFile = NULL;
		fopen_s(&pFile, "D:\\CatchFile1.txt", "wb");
		fwrite(txt, sizeof(char), strlen(txt), pFile);
		fclose(pFile);
		return false;
	}
	return true;	
}