Last active
December 8, 2020 04:51
-
-
Save MarsTechHAN/816d8c47ab4e65fcd125c9f5a8ce1c10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "net.h" | |
#include <algorithm> | |
#include <opencv2/core/core.hpp> | |
#include <opencv2/highgui/highgui.hpp> | |
#include <opencv2/imgproc/imgproc.hpp> | |
#include <stdio.h> | |
static int detect_ncnn_net(const cv::Mat& bgr) | |
{ | |
ncnn::Net ncnn_net; | |
ncnn_net.load_param("srnet.param"); | |
ncnn_net.load_model("srnet.bin"); | |
ncnn::Mat in = ncnn::Mat::from_pixels(bgr.data, ncnn::Mat::PIXEL_BGR2RGB, bgr.cols, bgr.rows); | |
ncnn::Extractor ex = ncnn_net.create_extractor(); | |
ex.input("data", in); | |
ncnn::Mat picture_out; ex.extract("fc", picture_out); | |
cv::Mat a(picture_out.h, picture_out.w, CV_8UC3); | |
picture_out.to_pixels(a.data, ncnn::Mat::PIXEL_BGR2RGB); | |
printf("\n>>>>>>%d,%d,%d\n", picture_out.c, picture_out.h, picture_out.w); | |
cv::imwrite("picture.jpg", a); | |
return 0; | |
} | |
int main(int argc, char** argv) | |
{ | |
if (argc != 2) | |
{ | |
fprintf(stderr, "Usage: %s [imagepath]\n", argv[0]); | |
return -1; | |
} | |
const char* imagepath = argv[1]; | |
cv::Mat m = cv::imread(imagepath, 1); | |
if (m.empty()) | |
{ | |
fprintf(stderr, "cv::imread %s failed\n", imagepath); | |
return -1; | |
} | |
detect_ncnn_net(m); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment