CPP Version
#include"cnpy.h"
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
int main()
{
Mat img(100, 100, CV_32FC3);
randu(img, Scalar(0, 0, 0), Scalar(255, 255, 255));
std::cout << img << std::endl;
img = img/255.0;
std::cout << img << std::endl;
float* tmp = (float*)img.data;
cnpy::npy_save("img.npy", tmp, {100,100,3},"w");
// cv::imwrite("img1.jpg", img);
}
Python Version
import numpy as np
import cv2
temp = np.load("img.npy")
print(temp)
# cv2.imwrite("img2.jpg", temp)
No comments:
Post a Comment