解图片存到Mat
作者:互联网
Mat Canvas::http_get_image(string url)
{
//http://192.168.0.129/cache/convert/58d17d693f85fb3708f95da032e4342e/0.png
string host = "";
string port = "80";
string page = "";
size_t datalen = 0;
int p2 = 0;
for (int i = 0; i < 2; i++)
{
p2 = url.find('/', i == 0 ? 0 : p2 + 1);
if (p2 == -1)
{
std::cout << "该字符似乎没有出现这么多次" << std::endl;
break;
}
}
int p3 = 0;
for (int i = 0; i < 3; i++)
{
p3 = url.find('/', i == 0 ? 0 : p3 + 1);
if (p3 == -1)
{
std::cout << "该字符似乎没有出现这么多次" << std::endl;
break;
}
}
host = url.substr(p2 + 1, p3 - p2 - 1);
page = url.substr(p3, url.length() - p3);
uint8_t * inImage = get(host, port, page, datalen);
Mat image;
if (datalen != 0)
{
std::vector<unsigned char> buff;
for (int i = 0; i < datalen; i++)
{
buff.push_back(inImage[i]);
}
image = imdecode(Mat(buff), CV_LOAD_IMAGE_COLOR);
}
else
{
cout << "没有读到文件" << endl;
}
return image;
}
标签:p2,std,Mat,int,cout,存到,图片,string 来源: https://blog.csdn.net/qq_37120714/article/details/118672455