Exemplo n.º 1
0
void rotate(IplImage *img)
{
	CvRect rect;
	IplImage *imgLine;
	rect.x=GlobalGandhiji.x+GlobalGandhiji.width;
	rect.y=GlobalGandhiji.y-5;
	rect.width=(int)((GlobalGandhiji.width)-5);
	rect.height=GlobalGandhiji.height+15;
	if(GlobalGandhiji.matchval!=-1 && rect.x>0 && rect.y>0 &&  rect.y+rect.height<= img->height && rect.x+rect.width<= img->width)
	{	
	
		imgLine=cropRectangle(img,rect);
		cvNamedWindow("imgLine",1);
		cvShowImage("imgLine",imgLine);
		IplImage* src1 = cvCreateImage(
		cvGetSize(imgLine), 8, 1 );

		cvCvtColor( imgLine, src1, CV_RGB2GRAY );

		IplImage* dst = cvCreateImage(
		cvGetSize(src1), 8, 1 );
		IplImage* color_dst = cvCreateImage(
		cvGetSize(src1), 8, 3 );
		CvMemStorage* storage =
		cvCreateMemStorage(0);
		CvSeq* lines = 0;
		int i;
		cvCanny( src1, dst,50, 150, 3 );
		//cvDilate( dst, dst, 0, 1 );
		cvNamedWindow("edgedest",1);
		cvShowImage("edgedest",dst);
		cvCvtColor( dst, color_dst, CV_GRAY2BGR );
		#if 1
		lines = cvHoughLines2( dst, storage,
		CV_HOUGH_STANDARD, 1, CV_PI/180, 30, 0, 0 );
		for( i = 0; i < MIN(lines->total,100); i++ )
		{
		float* line =
		(float*)cvGetSeqElem(lines,i);
		float rho = line[0];
		float theta = line[1];

		printf("theta = %f",(theta*180/3.142));
		CvPoint pt1, pt2;
		double a = cos(theta), b = sin(theta);
		double x0 = a*rho, y0 = b*rho;
		printf("a= %f  b=%f  x0=%f  y0=%f roh=%f\n", a,b,x0,y0,rho);
		pt1.x = cvRound(x0 + 1000*(-b));
		pt1.y = cvRound(y0 + 1000*(a));
		pt2.x = cvRound(x0 - 1000*(-b));
		pt2.y = cvRound(y0 - 1000*(a));
		printf("    x1 = %d, y1 = %d",pt1.x,pt1.y);
		printf("    x2 = %d, y2 = %d\n\n",pt2.x,pt2.y);

		//if((theta*180/3.142) < 100 && (theta*180/3.142) > 79 )
		cvLine( color_dst, pt1, pt2,
		CV_RGB(255,0,0), 3, 8 );
		}
		#else
		lines = cvHoughLines2( dst, storage,
		CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 30, 0, 0 );
		for( i = 0; i < lines->total; i++ )
		{
		CvPoint* line =
		(CvPoint*)cvGetSeqElem(lines,i);
		cvLine( color_dst, line[0], line[1],
		CV_RGB(255,0,0), 3, 8 );
		}
		#endif
		
		cvNamedWindow( "Hough", 1 );
		cvShowImage( "Hough", color_dst );



	}
	


	/*
	




*/




}
Exemplo n.º 2
0
//------------FUNCTION USED FOR MATCHING THE NUMBER IN THE NOTE------------
void numberMatch()
{

			for(int i=0;i<croppedimgcnt;i++)
			{
			//	printf("entered for %d",globalcnt);
				int minthreshx=(60*CroppedImage[i]->width/177);
				int maxthreshx =(106*CroppedImage[i]->width/147);
				int minthreshy =(22*CroppedImage[i]->height/72);
				int maxthreshy = (42*CroppedImage[i]->height/72);
			//	printf("inside for after initialization function numbermatch()");
				CvRect rectcrop;
				rectcrop.x=minthreshx;
				rectcrop.y=minthreshy;
				rectcrop.width=maxthreshx-minthreshx;
				rectcrop.height=maxthreshy-minthreshy;
				CroppedNumber[i] = cropRectangle(CroppedImage[i], rectcrop);
			//	printf("inside for after cropping function numbermatch()");
				//cvNamedWindow("croppednumber",1);
				//cvShowImage("croppednumber",CroppedNumber[i]);
				//cvWaitKey(5);
			
			

			//--------------NUMBER TEMPLATE MATCH---------------

			CvPoint		minloc, maxloc;
			double		minval, maxval;
			float max=-1;
			int index=-1;
			//--------4 TEMPLATES Number  OF Numbertpl----------
			for(int j=0; j<4;j++)
			{
				//IplImage *tpl=cvLoadImage(Gandhitpl[i]);
				IplImage *source = cvLoadImage(Numbertpl[j]);
				int tempheight=CroppedImage[i]->height*16/72;
				int tempwidth=source->width*tempheight/source->height;
				//declare a destination IplImage object with correct size, depth and channels
				IplImage *destination = cvCreateImage
				( cvSize( tempwidth,tempheight),source->depth, source->nChannels );

				//use cvResize to resize source to a destination image
				cvResize(source, destination);

				//cvNamedWindow("sourcenumber",1);
				//cvNamedWindow("destnumber",1);
				//cvShowImage("sourcenumber",source);
				//cvShowImage("destnumber",destination);

				//cvWaitKey(10);
				//cvDestroyWindow("sourcenumber");
				//cvDestroyWindow("destnumber");
				IplImage *tpl=destination;
		


				int res_width=CroppedNumber[i]->width-tpl->width+1;
				int res_height=CroppedNumber[i]->height-tpl->height+1;


				IplImage *res = cvCreateImage( cvSize( res_width, res_height ), IPL_DEPTH_32F, 1 );
				/* choose template matching method to be used */
				//cvMatchTemplate( img, tpl, res, CV_TM_SQDIFF );
				//cvMatchTemplate( img, tpl, res, CV_TM_SQDIFF_NORMED );
				//cvMatchTemplate( img, tpl, res, CV_TM_CCORR );
				//cvMatchTemplate( img, tpl, res, CV_TM_CCORR_NORMED );
				//cvMatchTemplate( img, tpl, res, CV_TM_CCOEFF );
				cvMatchTemplate( CroppedNumber[i], tpl, res, CV_TM_CCOEFF_NORMED );
				cvMinMaxLoc( res, &minval, &maxval,&minloc,&maxloc, 0);
		
				//cvNamedWindow("showtplmatch",1);
				//cvShowImage("showtplmatch",img);
				//printf("\n i= %d, max = %f",i,maxval);
				//	cvWaitKey(100);
				if(max<maxval)
					{
						max=maxval;
						index=j;
					}
				//cvReleaseImage( &source);
				//cvReleaseImage( &destination );
				}
	
	// ----- THE TPL NOTE FOR WHICH THE MATCH WAS MAXIMUM , THAT INDEX COUNT IS INCREMENTED 
				
			maxnumber[index]++;
			}
}
Exemplo n.º 3
0
	void PolygonalSkin::_rebuildGeometry()
	{
		if (mLinePoints.size() < 2) return;
		if (!mRenderItem || !mRenderItem->getRenderTarget()) return;

		mGeometryOutdated = false;

		// using mCurrentCoord as rectangle where we draw polygons

		// base texture coordinates
		FloatPoint baseVerticiesUV[4] =
		{
			FloatPoint(mCurrentTexture.left, mCurrentTexture.top),
			FloatPoint(mCurrentTexture.right, mCurrentTexture.top),
			FloatPoint(mCurrentTexture.right, mCurrentTexture.bottom),
			FloatPoint(mCurrentTexture.left, mCurrentTexture.bottom)
		};

		// UV vectors
		FloatPoint vectorU = baseVerticiesUV[1] - baseVerticiesUV[0];
		FloatPoint vectorV = baseVerticiesUV[3] - baseVerticiesUV[0];

		FloatPoint vertex1;
		FloatPoint vertex2;
		mResultVerticiesPos.clear();
		mResultVerticiesUV.clear();
		// add first two verticies
		FloatPoint normal = _getPerpendicular(mLinePoints[0], mLinePoints[1]);

		FloatPoint points[2] = {mLinePoints[0] + normal, mLinePoints[0] - normal};
		FloatPoint pointsUV[2] = {baseVerticiesUV[0], baseVerticiesUV[3]};
		// add other verticies
		float currentLength = 0.0f;
		for (size_t i = 1; i < mLinePoints.size(); ++i)
		{
			currentLength += len(mLinePoints[i - 1].left - mLinePoints[i].left,  mLinePoints[i - 1].top - mLinePoints[i].top);

			// getting normal between previous and next point
			if (i != mLinePoints.size() - 1)
				normal = _getMiddleLine(mLinePoints[i - 1], mLinePoints[i + 1], mLinePoints[i]);
			else
				normal = _getPerpendicular(mLinePoints[i - 1], mLinePoints[i]);

			bool edge = false;
			bool sharp = false;
			if (normal == FloatPoint() /*|| len(normal.left, normal.top) > mLineWidth * 2*/)
			{
				edge = true;
				normal = _getPerpendicular(mLinePoints[i - 1], mLinePoints[i]);
			}
			else if (len(normal.left, normal.top) > mLineWidth * 1.5)
			{
				sharp = true;
				normal = _getPerpendicular(mLinePoints[i - 1], mLinePoints[i]);
			}

			// check orientation
			FloatPoint lineDir = mLinePoints[i] - mLinePoints[i - 1];
			if (lineDir.left * normal.top - lineDir.top * normal.left < 0)
			{
				normal.left = -normal.left;
				normal.top = -normal.top;
			}

			FloatPoint UVoffset(currentLength / mLineLength * vectorU.left, currentLength / mLineLength * vectorU.top);

			mResultVerticiesPos.push_back(points[0]);
			mResultVerticiesPos.push_back(points[1]);
			mResultVerticiesPos.push_back(mLinePoints[i] + normal);
			mResultVerticiesUV.push_back(pointsUV[0]);
			mResultVerticiesUV.push_back(pointsUV[1]);
			mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);

			mResultVerticiesPos.push_back(points[1]);
			mResultVerticiesPos.push_back(mLinePoints[i] - normal);
			mResultVerticiesPos.push_back(mLinePoints[i] + normal);
			mResultVerticiesUV.push_back(pointsUV[1]);
			mResultVerticiesUV.push_back(baseVerticiesUV[3] + UVoffset);
			mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);

			points[edge ? 1 : 0] = mLinePoints[i] + normal;
			points[edge ? 0 : 1] = mLinePoints[i] - normal;
			pointsUV[0] = baseVerticiesUV[0] + UVoffset;
			pointsUV[1] = baseVerticiesUV[3] + UVoffset;

			if (sharp)
			{
				normal =  _getMiddleLine(mLinePoints[i - 1], mLinePoints[i + 1], mLinePoints[i]);

				float sharpness = len(normal.left, normal.top) / mLineWidth;

				float length = len(normal.left, normal.top);
				normal.left *= 2 * mLineWidth / length / (sharpness - 0.5f);
				normal.top *= 2 * mLineWidth / length / (sharpness - 0.5f);

				// check orientation
				lineDir = mLinePoints[i] - mLinePoints[i - 1];
				if (lineDir.left * normal.top - lineDir.top * normal.left < 0)
				{
					normal.left = -normal.left;
					normal.top = -normal.top;
				}
				FloatPoint lineDir1 = mLinePoints[i] - mLinePoints[i - 1];
				FloatPoint lineDir2 = mLinePoints[i + 1] - mLinePoints[i];
				if (lineDir1.left * lineDir2.top - lineDir1.top * lineDir2.left > 0)
				{
					normal.left = -normal.left;
					normal.top = -normal.top;
				}

				// check orientation
				FloatPoint normal2 = _getPerpendicular(mLinePoints[i], mLinePoints[i + 1]);
				lineDir = mLinePoints[i - 1] - mLinePoints[i];
				if ((lineDir.left * normal2.top - lineDir.top * normal2.left < 0))
				{
					normal2.left = -normal2.left;
					normal2.top = -normal2.top;
				}

				FloatPoint UVcenter((baseVerticiesUV[0].left + baseVerticiesUV[3].left) / 2, (baseVerticiesUV[0].top + baseVerticiesUV[3].top) / 2);
				mResultVerticiesPos.push_back(points[0]);
				mResultVerticiesPos.push_back(mLinePoints[i] + normal);
				mResultVerticiesPos.push_back(mLinePoints[i]);
				mResultVerticiesUV.push_back(pointsUV[0]);
				mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
				mResultVerticiesUV.push_back(UVcenter + UVoffset);

				mResultVerticiesPos.push_back(mLinePoints[i] + normal);
				mResultVerticiesPos.push_back(mLinePoints[i] + normal2);
				mResultVerticiesPos.push_back(mLinePoints[i]);
				mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
				mResultVerticiesUV.push_back(baseVerticiesUV[0] + UVoffset);
				mResultVerticiesUV.push_back(UVcenter + UVoffset);

				points[0] = mLinePoints[i] + normal2;
				points[1] = mLinePoints[i] - normal2;
				pointsUV[0] = baseVerticiesUV[0] + UVoffset;
				pointsUV[1] = baseVerticiesUV[3] + UVoffset;
			}
		}


#ifndef MYGUI_NO_POLYGONAL_SKIN_CROPPING
		// crop triangles
		IntCoord cropRectangle(
			mCurrentCoord.left,
			mCurrentCoord.top,
			mCurrentCoord.width,
			mCurrentCoord.height
			);

		VectorFloatPoint newResultVerticiesPos;
		VectorFloatPoint newResultVerticiesUV;
		newResultVerticiesPos.reserve(mResultVerticiesPos.size());
		newResultVerticiesUV.reserve(mResultVerticiesPos.size());
		for (size_t i = 0; i < mResultVerticiesPos.size(); i += 3)
		{
			VectorFloatPoint croppedTriangle =
				geometry_utility::cropPolygon(&mResultVerticiesPos[i], 3, cropRectangle);
			if (!croppedTriangle.empty())
			{
				FloatPoint v0 = mResultVerticiesUV[i + 2] - mResultVerticiesUV[i];
				FloatPoint v1 = mResultVerticiesUV[i + 1] - mResultVerticiesUV[i];

				for (size_t j = 1; j < croppedTriangle.size() - 1; ++j)
				{
					newResultVerticiesPos.push_back(croppedTriangle[0]);
					newResultVerticiesPos.push_back(croppedTriangle[j]);
					newResultVerticiesPos.push_back(croppedTriangle[j + 1]);

					// calculate UV
					FloatPoint point;
					point = geometry_utility::getPositionInsideRect(croppedTriangle[0], mResultVerticiesPos[i], mResultVerticiesPos[i + 1], mResultVerticiesPos[i + 2]);
					newResultVerticiesUV.push_back(geometry_utility::getUVFromPositionInsideRect(point, v0, v1, mResultVerticiesUV[i]));
					point = geometry_utility::getPositionInsideRect(croppedTriangle[j], mResultVerticiesPos[i], mResultVerticiesPos[i + 1], mResultVerticiesPos[i + 2]);
					newResultVerticiesUV.push_back(geometry_utility::getUVFromPositionInsideRect(point, v0, v1, mResultVerticiesUV[i]));
					point = geometry_utility::getPositionInsideRect(croppedTriangle[j + 1], mResultVerticiesPos[i], mResultVerticiesPos[i + 1], mResultVerticiesPos[i + 2]);
					newResultVerticiesUV.push_back(geometry_utility::getUVFromPositionInsideRect(point, v0, v1, mResultVerticiesUV[i]));
				}
			}
		}
		std::swap(mResultVerticiesPos, newResultVerticiesPos);
		std::swap(mResultVerticiesUV, newResultVerticiesUV);
#endif


		// now calculate widget base offset and then resulting position in screen coordinates
		const RenderTargetInfo& info = mRenderItem->getRenderTarget()->getInfo();
		float vertex_left_base = ((info.pixScaleX * (float)(mCroppedParent->getAbsoluteLeft()) + info.hOffset) * 2) - 1;
		float vertex_top_base = -(((info.pixScaleY * (float)(mCroppedParent->getAbsoluteTop()) + info.vOffset) * 2) - 1);

		for (size_t i = 0; i < mResultVerticiesPos.size(); ++i)
		{
			mResultVerticiesPos[i].left = vertex_left_base + mResultVerticiesPos[i].left * info.pixScaleX * 2;
			mResultVerticiesPos[i].top = vertex_top_base + mResultVerticiesPos[i].top * info.pixScaleY * -2;
		}
	}
Exemplo n.º 4
0
void doBlack(IplImage * img[50])
{
	CvRect *r1;
	 CvScalar s;
	 //printf(" cnt = %d", globalcnt);
	 
	for(int i=0;i<21;i++)
	{

		int thresholdminx = (int)(GlobalGandhiji[i].x-(GlobalGandhiji[i].width*172/45));
		int thresholdmaxx = (int)(GlobalGandhiji[i].x+(GlobalGandhiji[i].width*94/45));

 		int thresholdminy =(int)(GlobalGandhiji[i].y-(GlobalGandhiji[i].height*40/45));

		int thresholdmaxy = (int)(GlobalGandhiji[i].y+(GlobalGandhiji[i].height*75/45));
		
		

	int tempc=0;

		if(GlobalGandhiji[i].matchval!=-1 && thresholdminx>0 && thresholdminy>0 &&  thresholdmaxy<= img[i]->height && thresholdmaxx<= img[i]->width)
		{
			CvRect rectcrop;
			rectcrop.x=thresholdminx;
			rectcrop.y=thresholdminy;
			rectcrop.width=thresholdmaxx-thresholdminx;
			rectcrop.height=thresholdmaxy-thresholdminy;
			CroppedImage[croppedimgcnt] = cropRectangle(img[i], rectcrop);
			croppedimgcnt++;
			
			++tempc;
			
			for(int l=0;l<img[i]->height;l++)
			{
		//printf("....");
				for(int m=0;m<img[i]->width;m++)
				{
					if((m<thresholdminx || m> thresholdmaxx)  || (l< thresholdminy || l> thresholdmaxy))
					{ 
					
				
						s = cvGet2D(img[i], l, m);
		//	printf("hi.....");
			//	s.
			//	s.val[3]=0.0;
						s.val[0]=0.0;
						s.val[1]=0.0;
						s.val[2]=0.0;
			
						cvSet2D(img[i], l, m, s );
	
					}
			
			
				}
//		printf("over j");

			}


			//cvNamedWindow("showthres",1);
			//cvShowImage("showthres",img[i]);
			
			//cvWaitKey(500);

			//---------FIRST ATTEMPT TO DETERMINE THE DENOMINATION OF THE NOTE---------
			detectDenomination(img[i],thresholdmaxx-thresholdminx,thresholdmaxy-thresholdminy);
		}

	}

	

}