0
我想用openCV擴展一個給定persentage的矩形。我在下面爲它寫了一個函數。由於Rectengle類的x和y值是public,所以我必須在不使用getter或setter方法的情況下獲取並設置x和y值(儘管這個類沒有)。但是,我得到一行NullPointerException錯誤「temp.x = r.x-(tempWidth/2);」在調試期間。擴大一個方形openCV
會出現什麼問題? 感謝
public Rect extendRect(Rect r,double persent,int bmpWidth,int bmpHeight)
{
Rect temp = Rect(0,0);
int tempWidth =(int)(r.width*persent+(double)r.width);
int tempHeight =(int)(r.height*persent+(double)r.height);
temp.x=r.x-(tempWidth/2);// orginal rect
temp.width=tempWidth;
temp.y=r.y-(tempHeight/2);
temp.height=tempHeight;
//boundary check
if((temp.x+temp.width)>bmpWidth)
{
temp.width = bmpWidth-temp.x;
}
if(temp.x<0)
{
temp.x=0;
}
if((temp.y+temp.height)>bmpHeight)
{
temp.height =bmpHeight-temp.y;
}
if(temp.y<0)
{
temp.y=0;
}
return temp;
}
不要給構造函數一些寬度和高度嗎? 'Rect temp = Rect(0,0,width,height);' – Micka
你說得對。由於編譯器(日食)沒有給出任何錯誤,我認爲這是正確的。 – user3079364