반응형
논문 제목 : Computer vision for computer games
http://www.merl.com/papers/docs/TR96-35.pdf
CAM-Shift에도 같은 내용이 들어있음.
float GetTheta(CSvImage& coloring, BLOBELE& boundbox) { double xc=0, yc=0; int cnt =0; vector<CPoint> vPoint; for(int y= boundbox.rt.top; y<= boundbox.rt.bottom; y++) { for(int x= boundbox.rt.left; x<= boundbox.rt.right; x++) { if(coloring.GetPixel(x,y) == boundbox.Coloring) { xc += x; yc += y; vPoint.push_back(CPoint(x,y)); } } } xc /= vPoint.size(); yc /= vPoint.size(); for(int i=0; i< vPoint.size(); i++) { vPoint.at(i).x -= xc; vPoint.at(i).y -= yc; } double m00 = vPoint.size(); double m11=0, m02=0, m20=0; for(int i=0; i< vPoint.size(); i++) { m11 += (vPoint.at(i).x * vPoint.at(i).y); m20 += (vPoint.at(i).x * vPoint.at(i).x); m02 += (vPoint.at(i).y * vPoint.at(i).y); } double a = m20 / m00 ; double b = 2 * (m11/m00); double c = m02/m00 ; double theta = atan2(b, (a-c))/2; double l1 = sqrt( ( (a+c) + sqrt(b*b + (a-c)*(a-c)) )/ 2); double l2 = sqrt( ( (a+c) - sqrt(b*b + (a-c)*(a-c)) )/ 2); int lpx = (l1) * cos(theta) ; int lpy = (l1) * sin(theta) ; // cvLine(coloring.m_Buff, cvPoint(xc,yc), cvPoint(xc + lpx, yc+lpy), cvScalar(0,0,255), 2); // cvShowImage("anlge", coloring.m_Buff); // cvWaitKey(0); if(theta < 0 ) { theta += CV_PI*2; } float aaa = theta/CV_PI *180; return theta/CV_PI *180; }
반응형
'Study > 컴퓨터비전' 카테고리의 다른 글
이미지 와핑 Image Warping (0) | 2019.06.05 |
---|---|
Median Filter (0) | 2013.12.06 |
CAM-Shift ( Computer Vision Face Tracking For Use in a Perceptual User Interface) (1) | 2013.12.03 |