opencv图像格式转换

更新时间:2023-05-25 14:08:07 阅读: 评论:0

opencv图像格式转换
extern"C" _declspec(dllexport) BYTE* __stdcall ImageConvert(BYTE* imageData, int imageDataSize, const char* format, int* returnSize) {
vector<uchar> data;
for (int i = 0; i < imageDataSize; ++i) {
data.push_back(imageData[i]);
}
印章十不刻cv::Mat image = cv::imdecode(data, CV_LOAD_IMAGE_COLOR);
std::vector<uchar> buf;
imencode(format, image, buf);
*returnSize = buf.size();
BYTE* result = new BYTE[*returnSize];
for (int i = 0; i < *returnSize; i++)
节日庆典result[i] = buf[i];
return result;
}
JAVA调⽤代码:
import java.io.IOException;
唐朝女子妆容import java.nio.file.Files;
import java.nio.file.Paths;
白羊座男生喜欢什么样的女生import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
public class Program {
劲脆鸡腿堡public interface Lib extends Library
{
public Pointer ImageConvert(Pointer data, int dataSize, String format , Pointer resultSize);
}
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
Lib lib = (Lib) Native.loadLibrary("..\\OpenCVDemo.dll", Lib.class);
byte[] data = ("..\\01.tif"));
Pointer ptr = new Memory(data.length);
听课记录怎么写ptr.write(0, data, 0, data.length);
Pointer returnSize = new Memory(4);
Pointer result = lib.ImageConvert(ptr, data.length, ".png" , returnSize);
byte[] resultData = ByteArray(0, Int(0));
Files.("..\\01.png"), resultData);
System.out.println("ok");
}
}
追加:
下⾯这个可能更⾼效:
extern"C" _declspec(dllexport) BYTE* __stdcall ImageConvert(BYTE* imageData, int imageDataSize, const char* format, int* returnSize) {
//convert byte[] to vector<uchar>炒肝的家常做法
std::vector<uchar> data(imageData, imageData + imageDataSize);
//convert image format
cv::Mat image = cv::imdecode(data, CV_LOAD_IMAGE_COLOR);
std::vector<uchar> buf;
imencode(format, image, buf);
双子女和金牛男//covert vector<uchar> to byte[]
*returnSize = buf.size();
BYTE* result = new BYTE[*returnSize];
std::copy(buf.begin(), d(), result);
return result;
}

本文发布于:2023-05-25 14:08:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/929002.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:男生   炒肝   转换   妆容
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图