OpenCV Native 开发环境搭建步骤请参考:
OpenCV Native开发环境搭建_tugouxp的专栏-CSDN博客
YOLOV3网络吃图格式为416*416 NCWH 三通道的RGB格式图,下面的程序可以将一张JPEG图像转换为对应的格式,基于OPENCV
#include
#include
#include
#include
using namespace std;
using namespace cv;
int main(int argc, char **argv)
{
Mat img = imread("output_416x416.jpg");
if(img.empty())
{
cout <<"please confirm the name of pic is right!" < it0 = imgs0.begin();
cv::MatIterator_ it0_end = imgs0.end();
for (int i = 0; it0 != it0_end; it0 ++, i ++)
{
unsigned char data = *it0;
int count = fwrite(&data, 1, 1, file);
if(count != 1)
{
cout << "write binary failure." << endl;
}
}
cv::MatIterator_ it1 = imgs1.begin();
cv::MatIterator_ it1_end = imgs1.end();
for (int i = 0; it1 != it1_end; it1 ++, i ++)
{
unsigned char data = *it1;
int count = fwrite(&data, 1, 1, file);
if(count != 1)
{
cout << "write binary failure." << endl;
}
}
cv::MatIterator_ it2 = imgs2.begin();
cv::MatIterator_ it2_end = imgs2.end();
for (int i = 0; it2 != it2_end; it2 ++, i ++)
{
unsigned char data = *it2;
int count = fwrite(&data, 1, 1, file);
if(count != 1)
{
cout << "write binary failure." << endl;
}
}
fsync(fileno(file));
fflush(file);
fclose(file);
waitKey(0);
return 0;
}
scale 为416*416大小
#include
#include
#include
#include
using namespace std;
using namespace cv;
static void print_type(void)
{
printf("CV_8UC1=%d.\n", CV_8UC1);
printf("CV_8UC2=%d.\n", CV_8UC2);
printf("CV_8UC3=%d.\n", CV_8UC3);
printf("CV_8UC4=%d.\n", CV_8UC4);
printf("CV_8SC1=%d.\n", CV_8SC1);
printf("CV_8SC2=%d.\n", CV_8SC2);
printf("CV_8SC3=%d.\n", CV_8SC3);
printf("CV_8SC4=%d.\n", CV_8SC4);
printf("CV_16UC1=%d.\n", CV_16UC1);
printf("CV_16UC2=%d.\n", CV_16UC2);
printf("CV_16UC3=%d.\n", CV_16UC3);
printf("CV_16UC4=%d.\n", CV_16UC4);
printf("CV_16SC1=%d.\n", CV_16SC1);
printf("CV_16SC2=%d.\n", CV_16SC2);
printf("CV_16SC3=%d.\n", CV_16SC3);
printf("CV_16SC4=%d.\n", CV_16SC4);
printf("CV_32SC1=%d.\n", CV_32SC1);
printf("CV_32SC2=%d.\n", CV_32SC2);
printf("CV_32SC3=%d.\n", CV_32SC3);
printf("CV_32SC4=%d.\n", CV_32SC4);
printf("CV_32FC1=%d.\n", CV_32FC1);
printf("CV_32FC2=%d.\n", CV_32FC2);
printf("CV_32FC3=%d.\n", CV_32FC3);
printf("CV_32FC4=%d.\n", CV_32FC4);
printf("CV_64FC1=%d.\n", CV_64FC1);
printf("CV_64FC2=%d.\n", CV_64FC2);
printf("CV_64FC3=%d.\n", CV_64FC3);
printf("CV_64FC4=%d.\n", CV_64FC4);
return;
}
int main(int argc, char **argv)
{
print_type();
Mat img = imread("dog.jpg");
if(img.empty())
{
cout <<"please confirm the name of pic is right!" < it0 = imgs0.begin();
cv::MatIterator_ it0_end = imgs0.end();
for (int i = 0; it0 != it0_end; it0 ++, i ++)
{
unsigned char data = *it0;
int count = fwrite(&data, 1, 1, file);
if(count != 1)
{
cout << "write binary failure." << endl;
}
}
cv::MatIterator_ it1 = imgs1.begin();
cv::MatIterator_ it1_end = imgs1.end();
for (int i = 0; it1 != it1_end; it1 ++, i ++)
{
unsigned char data = *it1;
int count = fwrite(&data, 1, 1, file);
if(count != 1)
{
cout << "write binary failure." << endl;
}
}
cv::MatIterator_ it2 = imgs2.begin();
cv::MatIterator_ it2_end = imgs2.end();
for (int i = 0; it2 != it2_end; it2 ++, i ++)
{
unsigned char data = *it2;
int count = fwrite(&data, 1, 1, file);
if(count != 1)
{
cout << "write binary failure." << endl;
}
}
fsync(fileno(file));
fflush(file);
fclose(file);
waitKey(0);
return 0;
}
scale.jpg文件是缩放后的图像。