报错:java.lang.ArithmeticException:divide by zero

展开阅读全文

opencv中未使用除法仍然出现Integer division by zero的问题?

04-09

如图1、2所示程序,程序中并没有使用除法,但仍然出现了被除数不能为0的问题,求大佬解惑! ![图片说明](https://img-ask.csdn.net/upload/201804/09/1523256900_644910.png) ![图片说明](https://img-ask.csdn.net/upload/201804/09/1523256928_956560.png) ![图片说明](https://img-ask.csdn.net/upload/201804/09/1523256943_667989.png) 代码如下: ``` #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc, char**argv) { Mat image, img; image = imread("D:\\VS2013\\1.bmp"); img = image.clone(); Mat gray_image; cvtColor(img, gray_image, CV_BGR2GRAY); Mat thre_image; threshold(gray_image, thre_image, 120, 255, CV_THRESH_BINARY); Mat erode_image, dilate_image; Mat element = getStructuringElement(MORPH_RECT, Size(5, 5)); erode(thre_image, erode_image, element); dilate(erode_image, dilate_image, element); vector<vector<Point>> contours; vector<cv::Mat> rois; findContours(dilate_image, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); for (int i = 0; i<(int)contours.size(); i++) //分割的个数 { double x = contourArea(contours[i]);//i个分割部分的面积 if (x > 71000) { Rect boundrect = boundingRect(contours[i]); Mat ROI = img(boundrect).clone(); rois.push_back(ROI); } } for (int j = 0; j<(int)rois.size(); j++) { char filename[500]; sprintf_s(filename, "%s%d%s", "D:\\fenge\\", j, ".jpg"); imwrite(filename, rois[j]); //string Img_Name = "D:/fenge/" + to_string(j) + ".jpg"; //imwrite(Img_Name, rois[j]); } // imshow("test", img); waitKey(); system("pause"); return 0; } ``` 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览