如何查找轮廓上具有特定度数的点(Opencv)

如何查找轮廓上具有特定度数的点(Opencv),opencv,point,contour,angle,Opencv,Point,Contour,Angle,我有轮廓的点,我想得到特定度数的点的(x,y)。从附加的图像,我想得到黄点 我使用了@Aleksander和@Zaw给我的暗示。 轮廓的质心被用作一个点来绘制直线,我使用直线方程得到每条直线的第二个点并绘制它 y - y1 = m (x - x1) 为了得到m,我们使用了以下方程式 arctan( **y** of the centroid / **x** of the centroid) - angle in radiant = Phi tan(Phi) = m 然后我用 y = m

我有轮廓的点,我想得到特定度数的点的(x,y)。从附加的图像,我想得到黄点


我使用了@Aleksander和@Zaw给我的暗示。 轮廓的质心被用作一个点来绘制直线,我使用直线方程得到每条直线的第二个点并绘制它

y - y1 = m (x - x1)
为了得到m,我们使用了以下方程式

arctan( **y** of the centroid / **x** of the centroid) - angle in radiant = Phi

tan(Phi) = m 
然后我用

y = m (x - x1) + y1
当x1和y1是质心点,x是绘制直线所需的第二个点的假定坐标时

void MyDraw (Mat Draw, vector<Point> hull,Scalar color,int thickness){
  std::vector<std::vector<cv::Point> > T = std::vector<std::vector<cv::Point> >(1,hull); 
  drawContours(Draw, T, -1, color, thickness);} 

Point GetCentroidOfConvexHull(vector<Point> Hull){
// Get the moments
  Moments mu;
  mu= moments(Hull, false );
// Get the mass centers:
  return Point( mu.m10/mu.m00 , mu.m01/mu.m00 );}   



void _tmain(int argc, _TCHAR* argv[]){ 
    vector<vector<Point>> contours;
    vector<Point> hull;
    Mat testContour = Mat::zeros(width, height,CV_8UC3);
    Mat testLine = Mat::zeros(width, height,CV_8UC3);
    Mat andResult;
    Point centroid;

    findContours(Dilated,contour,hierarchy,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE,Point (0,0));
    convexHull(contour,hull,false);
    centroid = GetCentroidOfConvexHull(hull);
    MyDraw(testContour,hull,White,1);
    Rect myRect = boundingRect(hull);
    imshow("test contour",testContour);
    waitKey(0);
    float degrees[8] = {0,45,90,135,180,225,270,315};
    Point point;
    // for each degree                
    for (int d = 0 ; d < 8 ; d++){
       //Get line equation from the slope and the center point of the contour
       float m = std::tan( std::atan2((double)centroid.y,(double)centroid.x) - (degrees[d]*3.14/180));
       // using the upper left and lower right points to get the x of the other point
       if ((d >= 0 && d <= 2) || d == 7) point.x = myRect.tl().x;
       else point.x = myRect.br().x;
       point.y = (int)(m * (float)(point.x - centroid.x) + centroid.y);
       line(testLine,centroid,point,White,1,8);}

       imshow("test Line",testLine);
       waitKey(0);
       // and operation
       andResult = testContour & testLine;
       imshow("Anding Result",andResult);
       waitKey(0);}
void MyDraw(Mat-Draw、向量外壳、标量颜色、int-thickness){
std::vector T=std::vector(1,外壳);
绘制轮廓(绘制,T,-1,颜色,厚度);}
圆心点(向量壳){
//抓住机会
乌木;
mu=力矩(外壳,假);
//获取质量中心:
返回点(mu.m10/mu.m00,mu.m01/mu.m00);}
void _tmain(int argc,_TCHAR*argv[]){
矢量等值线;
向量壳;
Mat testContour=Mat::零(宽度、高度、CV_8UC3);
Mat测试线=Mat::零(宽度、高度、CV_8UC3);
Mat andResult;
点形心;
findContours(扩展、轮廓、层次、CV_RETR__外部、CV_CHAIN_近似、无、点(0,0));
凸形轮(外形、外壳、假);
质心=GetConvexhull(船体)的质心;
MyDraw(测试轮廓,外壳,白色,1);
Rect myRect=boundingRect(外壳线);
imshow(“测试轮廓”,testContour);
等待键(0);
浮动度数[8]={0,45,90135180225270315};
点-点;
//每度
对于(int d=0;d<8;d++){
//从等高线的坡度和中心点获取直线方程
浮点数m=std::tan(std::atan2((双)形心y,(双)形心x)-(度[d]*3.14/180));
//使用左上角和右下角点获取另一点的x

如果((d>=0&&d)你所说的“度”是什么意思?你是在寻找一些线以一个角度分开的交叉点吗?还有,你试过什么吗?不,我没有试过任何东西,因为我不知道怎么做。但我会尝试你的提示,谢谢。好吧,这不是一个提示,而是一个澄清的要求,但我想当你从这样的角度看问题时我知道你可以在
OpenCV
中用多项式近似轮廓。如果你这样做,并将直线描述为一阶多项式,你可以解析地找到交点。漂亮、简单、快速。通过在两个独立的imag上绘制轮廓和直线,你可以相当容易地找到交点es并执行逻辑and。然后生成的图像将是您的黄点。红十字的中心是质心吗?@ZawLin是的,我正试图通过对两个单独的图像进行ANDing来解决它。但现在我在画线时遇到了一个问题。如果无法进一步了解,我将提供代码来讨论它:D。