2012-05-06 94 views
-5

幫助我如何SOVE它,[當t嘗試EXECUT我的代碼,一個警告窗口] [1]例外非géréeà0x100e3cf2丹斯shervinemami.exe:0xC0000094:整數除以零

注意到調試罰款並且成功,但是當嘗試執行代碼時,我會在輸出窗口中收到消息;例外非géréeà0x100e3cf2丹斯shervinemami.exe:0xC0000094:整數除以zero..which意味着存在由零dision的異常,這是代碼:

 IplImage* LOULILI::cropFace(IplImage*image, CvPoint eye_left, CvPoint eye_right,double offset_pct[2], CvSize dest_sz) 
      { 
     //calculate offsets in original image 
      double offset_h = offset_pct[0]* dest_sz.width; 
      double offset_v = offset_pct[1]*dest_sz.height; 
      //get the direction 
      double eye_directionX,eye_directionY; 
      eye_directionX= double(eye_right.x - eye_left.x); 
      eye_directionY=double(eye_right.y - eye_left.y); 
      // calc rotation angle in radians 
      double rotation; 
      rotation = double(-atan2(eye_directionY,eye_directionX)*180/PI); 
      // distance between them 
      double dist = distancePoints(eye_left, eye_right); 
      //calculate the reference eye-width 
      double reference = dest_sz.width - 2.0*offset_h; 
      //scale factor 
       double scale = dist/reference; 
      //rotation par rapport à l'oeil gauche 
     //matrice de rotation 
     cv::Mat affine_matrix; 
     affine_matrix =cv::getRotationMatrix2D(eye_left, rotation, scale); 
      //mtx est la conversion de image IplImage* en matrice mtx 
      cv::Mat mtx=cv::Mat(image,true); 
      cv::Mat mtx2; 
     cv::warpAffine(mtx, mtx2, affine_matrix,mtx.size(),cv::INTER_LINEAR,        cv::BORDER_CONSTANT,cv::Scalar::all(255)); 
    //mtx est la conversion de matrice mtx2 en image IplImage* 
    //IplImage* image1 =&mtx2.operator IplImage(); 
IplImage image1 =mtx2; 
IplImage* im22=(IplImage*)&image1; 
     //crop the rotated image 
     double crop_x =double(eye_left.x) - scale*offset_h; 
     double crop_y =double(eye_left.y) - scale*offset_v; 

double crop_size0 = (double)dest_sz.width*scale; 
    double crop_size1= (double) dest_sz.height*scale; 
     CvRect region; 
     region.x=cvRound(crop_x); 
     region.y=cvRound(crop_y); 
     region.width=cvRound (crop_size0); 
     region.height=cvRound(crop_size1); 

      IplImage* im44=cropImage(im22,region); 
      //crop((int(crop_xy[0]), int(crop_xy[1]), int(crop_xy[0]+crop_size[0]),      int(crop_xy[1]+crop_size[1]))) 

      IplImage* image3=resizeImage(im44, dest_sz.width, dest_sz.width); 
      return im44; 
        } 
+5

因此,在您發佈的代碼中,只有一個除法操作'dist/reference' - 我想我會從那裏開始... – jedwards

+0

Visual Studio會告訴您錯誤是什麼行...您是在某個地方除以零,所以只要看看錯誤在哪一行,並確保你不會被零除! –

+1

是的,這裏的結論與jedwards相同 - 根據你向我們展示的內容,我會檢查PI是否被恰當地定義爲常量。 –

回答

0

沒有整數除法在於代碼,所以我們無法提供幫助。您可能想要在調試模式下進行編譯,並將調試器設置爲在C++異常中斷(可以在Visual Studio的異常窗口中執行此操作)。

+0

你能告訴我怎麼樣嗎? – OntoBLW