//点在哪个象限
short isAtQuadrantal (int x0,int y0, int x1, int y1){
if( (x0 != x1 && x0 != y1) || (y0 != x1 && y0 != y1) ){
return -1;
}
if(x0 < x1){
return 0;
}
if(y0 > y1){
return 90;
}
if(x0 > x1){
return 180;
}
if(y0 < y1){
return 270;
}
}
//获取斜线上的所有坐标点,必须是斜线
void getObliqueLineAllPoint(int x0,int y0, int x1, int y1, vector<cv::Point> &points, float precision = 0.1f){
short isQuadrantal = isAtQuadrantal(x0,x1,x1,y1);
if(isQuadrantal != -1){
if(isQuadrantal == 0 || isQuadrantal == 180){
int increase = (x0-x1) > 0 ? -1 : 1;
int x = x0 + increase;
for (int i = 0; i < abs(x0-x1)-1; i++){
points.push_back(cv::Point(x,y0));
x += increase;
}
}else{
int increase = (y0-y1) > 0 ? -1 : 1;
int y = y0 + increase;
for (int i = 0; i < abs(y0-y1)-1; i++){
points.push_back(cv::Point(x0,y));
y += increase;
}
}
return;
}
float slope = getSlope(x0,y0,x1,y1);
float x = x0;
float y;
for (float i = 0; i < abs(x1-x0); i+=precision){
//计算y轴坐标
y = slope*(x-x0)+y0;//当已知斜率k,和一点坐标(x1,y1)时,常使用点斜式: y-y1 = k(x-x1)
points.push_back(cv::Point(x,y));
if (x0 < x1)
x+=precision;
else
x-=precision;
}
}
C++_OpenCV_获取斜线上的所有坐标点
最新推荐文章于 2023-04-04 10:46:15 发布