1、说明:
测试的opencv版本为opencv3.4.5
电脑cup:Intel® Xeon(R) W-2125 CPU @ 4.00GHz × 8
2、下载ENet的配置文件:
见https://www.pyimagesearch.com/2018/09/03/semantic-segmentation-with-opencv-and-deep-learning/里面的下载链接
3、C++代码:
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
void colorizeSegmentation(const cv::Mat &score, cv::Mat &segm, std::vector<cv::Vec3b> &colors) {
// score.size = 1 x 20 x 512 x 1024
const int chns = score.size[1];
const int rows = score.size[2];
const int cols = score.size[3];
cv::Mat maxCl = cv::Mat::zeros(rows, cols, CV_8UC1);
cv::Mat maxVal(rows, cols, CV_32FC1, score.data);
for (int ch = 1; ch < chns; ch++)
{
for (int row = 0; row < rows; row++)
{
const float *ptrScore = score.ptr<float>(0, ch, row);
uint8_t *ptrMaxCl = maxCl.ptr<uint8_t>(row);
float *ptrMaxVal = maxVal.ptr<float>(row);
for (int col = 0; col < cols; col++)
{
if (ptrS