计算miou完整代码
时间: 2024-04-28 16:18:52 浏览: 222
计算 语义分割结果 MIOU,miou.py操作简单,输出结果清晰
下面是计算MIOU的完整代码:
```cpp
#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
double MIOU(cv::Mat image_ground, cv::Mat image_daice) {
double jiaoji = 0.0;
double duli_ground = 0.0;
double duli_daice = 0.0;
double bingji = 0.0;
double iou = 0.0;
for (int i = 0; i < image_ground.cols; i++) {
for (int j = 0; j < image_ground.rows; j++) {
if ((image_ground.at<uchar>(j, i) == 255) && (image_daice.at<uchar>(j, i) == 255))
jiaoji += 1.0;
if (image_ground.at<uchar>(j, i) == 255)
duli_ground += 1.0;
if (image_daice.at<uchar>(j, i) == 255)
duli_daice += 1.0;
}
}
bingji = duli_ground + duli_daice - jiaoji;
iou = (double)(jiaoji / bingji);
return iou;
}
int main() {
double sum = 0.0;
double miou = 0.0;
for (int i = 0; i <= 99; i++) {
cv::Mat image_ground = cv::imread("C:/Users/Desktop/数据集/" + std::to_string(i) + ".png", CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat image_daice = cv::imread("C:/Users/Desktop/开发工程/" + std::to_string(i) + "_threshold.png", CV_LOAD_IMAGE_GRAYSCALE);
double iou_meige = MIOU(image_ground, image_daice);
sum += iou_meige;
}
miou = sum / 100.0;
std::cout << "MIOU: " << miou << std::endl;
return 0;
}
```
请注意,这只是一个示例代码,路径和文件名需要根据实际情况进行修改。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* *2* [图像分割评价指标---mIoU(平均交并比)计算代码(OpenCV/C++)](https://blog.csdn.net/Lujiahao98689/article/details/102289757)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文