2013-06-26 169 views

回答

0

在原矩陣A點(x,y)將在新的矩陣由

(x',y') = 2*(x,y)/3. 

減少到OpenCV的功能映射到(x',y')我們:

cv::Point scale_point(cv::Point p) // p is location in 960*720 Mat 
{ 
    return 2 * p/3; // return location in 640*480 Mat 
} 
+0

雖然這個概念上回答了這個問題,它不會在OpenCV的情況下解決這一問題。 – Dale

+0

我添加了Opencv代碼將其放入上下文中 – Bull

0

我最終行動做什麼是創建一個ScaledPoint對象,該對象擴展了Point。這樣一來,它就不會破壞我剛剛使用的純代碼對象的代碼。

public class ScaledPoint extends Point { 
    public ScaledPoint (double[] points, double scale) { 
     super(points[0] * scale, points[1] * scale); 
    } 
} 

然後,我計算出的比例因子和我擴展的類中使用它:

Mat originalObject; 
// TODO: populate the original object 
Mat scaledObject; 
// TODO: populate the scaled object 
double scaleFactor = scaledObject.getHeight()/(double)originalObject.getHeight(); 
matOfSomePoints = new Mat(4,1, CvType.CV_23FC2); 
// TODO: populate the above matrix with your points 
Point aPointForTheUnscaledImage = new Point(matOfSomePoints.get(0,0)); 
Point aPointForTheScaledImage = new ScaledPoint(matOfSomePoints.get(0,0), scaleFactor);