bool OBB::intersects(const OBB& box) const { float min1, max1, min2, max2; for (int i = 0; i < 3; i++) { getInterval(*this, getFaceDirection(i), min1, max1); getInterval(box, getFaceDirection(i), min2, max2); if (max1 < min2 || max2 < min1) return false; } for (int i = 0; i < 3; i++) { getInterval(*this, box.getFaceDirection(i), min1, max1); getInterval(box, box.getFaceDirection(i), min2, max2); if (max1 < min2 || max2 < min1) return false; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Vec3 axis; Vec3::cross(getEdgeDirection(i), box.getEdgeDirection(j), &axis); getInterval(*this, axis, min1, max1); getInterval(box, axis, min2, max2); if (max1 < min2 || max2 < min1) return false; } } return true; }
void getV_HBoundary(double *src,double *dst,int width,int height,double v_threshold,double a_threshold,int isVertical){ double *dst_v=(double *)malloc(sizeof(double)*width*height); double *dst_a=(double *)malloc(sizeof(double)*width*height); double *dst_d=(double *)malloc(sizeof(double)*width*height); double *temp=(double *)malloc(sizeof(double)*width*height); Scharr(src, dst_v, dst_a, width, height); getEdgeDirection(dst_a, dst_d, width, height); Non_MaxSuppression(dst_v, temp, dst_d, width, height); BoundaryDetection(temp, dst, dst_a, width, height, v_threshold, a_threshold,isVertical); free(dst_a); free(dst_v); free(dst_d); free(temp); }
void Canny(double *src,double *dst,int width,int height,int sobel_size,double threshold1,double threshold2){ double *temp=(double *)malloc(sizeof(double)*width*height); double *edge_a=(double *)malloc(sizeof(double)*width*height);//边缘幅度 double *edge_d=(double *)malloc(sizeof(double)*width*height);//边缘方向 double *threshold_max=(double *)malloc(sizeof(double)*width*height); double *threshold_min=(double *)malloc(sizeof(double)*width*height); /********************************************************************* *step1:gaussian smooth *********************************************************************/ double gaussianmask[25]={ 2, 4, 5, 4, 2, 4, 9,12, 9, 4, 5,12,15,12, 5, 4, 9,12, 9, 4, 2, 4, 5, 4, 2}; RealConvolution(src, temp, gaussianmask, width, height, 5, 5); matrixMultreal(temp, temp, 1.0/159.0, width, height); /********************************************************************* *step2:sobel *********************************************************************/ if(sobel_size==3) Scharr(temp, edge_a, edge_d, width, height); else if(sobel_size==5||sobel_size==7) Sobel(temp, edge_a, edge_d, width, height,sobel_size); /********************************************************************* *step3:Non_MaxSuppression *********************************************************************/ getEdgeDirection(edge_d, edge_d, width, height); Non_MaxSuppression(edge_a, temp, edge_d, width, height); /********************************************************************* *step4:double threshold *********************************************************************/ Threshold(temp, threshold_max, width, height, threshold1, THRESHOLD_TYPE1); Threshold(temp, threshold_min, width, height, threshold2, THRESHOLD_TYPE1); NonZeroSetOne(threshold_max,threshold_max,width,height); NonZeroSetOne(threshold_min,threshold_min,width,height); for(int j=0;j<height;j++){ for(int i=0;i<width;i++){ if(threshold_max[j*width+i]==1.0&&threshold_min[j*width+i]!=2.0){ Position p; p.x=i; p.y=j; EdgeTrack(threshold_min, width, height, &p); } } } /********************************************************************* *step5:result *********************************************************************/ Zero(dst, width, height); for(int i=0;i<width*height;i++) if(threshold_min[i]==2.0) dst[i]=255.0; free(temp); free(threshold_max); free(threshold_min); free(edge_d); free(edge_a); }