Browse Source

visualize Mat

tags/20200413
nihuini 6 years ago
parent
commit
17bf5247cc
1 changed files with 55 additions and 1 deletions
  1. +55
    -1
      docs/Home.md

+ 55
- 1
docs/Home.md View File

@@ -36,7 +36,7 @@ int main()

### print Mat content
```
void pretty_print(const Mat& m)
void pretty_print(const ncnn::Mat& m)
{
for (int q=0; q<m.c; q++)
{
@@ -55,6 +55,60 @@ void pretty_print(const Mat& m)
}
```

### visualize Mat content
```
void visualize(const char* title, const ncnn::Mat& m)
{
std::vector<cv::Mat> normed_feats(m.c);

for (int i=0; i<m.c; i++)
{
cv::Mat tmp(m.h, m.w, CV_32FC1, (void*)(const float*)m.channel(i));

cv::normalize(tmp, normed_feats[i], 0, 255, cv::NORM_MINMAX, CV_8U);

cv::cvtColor(normed_feats[i], normed_feats[i], cv::COLOR_GRAY2BGR);

// check NaN
for (int y=0; y<m.h; y++)
{
const float* tp = tmp.ptr<float>(y);
uchar* sp = normed_feats[i].ptr<uchar>(y);
for (int x=0; x<m.w; x++)
{
float v = tp[x];
if (v != v)
{
sp[0] = 0;
sp[1] = 0;
sp[2] = 255;
}

sp += 3;
}
}
}

int tw = m.w < 10 ? 32 : m.w < 20 ? 16 : m.w < 40 ? 8 : m.w < 80 ? 4 : m.w < 160 ? 2 : 1;
int th = (m.c - 1) / tw + 1;

cv::Mat show_map(m.h * th, m.w * tw, CV_8UC3);
show_map = cv::Scalar(127);

// tile
for (int i=0; i<m.c; i++)
{
int ty = i / tw;
int tx = i % tw;

normed_feats[i].copyTo(show_map(cv::Rect(tx * m.w, ty * m.h, m.w, m.h)));
}

cv::resize(show_map, show_map, cv::Size(0,0), 2, 2, cv::INTER_NEAREST);
cv::imshow(title, show_map);
}
```

### caffe-android-lib+openblas vs ncnn
use squeezenet v1.1, nexus6p, android 7.1.2



Loading…
Cancel
Save