unity里面使用opencv,qt建立plugin(一)

unity里面使用opencv,qt建立plugin(一),第1张

1、unity

unity是一个非常良好的工具,简单易用,如何在unity中使用opencv?有两种方式,一种是把rgba传输过去,建一个服务接收,一种则是使用插件方式,对于熟悉动态库的人来说,比较简单。

2、使用qt建立动态链接库

qt 里面建立一个动态链接库,选择mingw 64

使用qt的好处是建立动态库同时适应多个 *** 作系统


#include "imagelib_global.h"
struct Color32
{
    uchar r;
    uchar g;
    uchar b;
    uchar a;
};
extern "C"
{
IMAGELIB_EXPORT void ImageProcess(Color32* raw, int width, int height);
}
#endif // IMAGELIB_H
/
#include "imagelib.h"
extern "C"
{

void ImageProcess(Color32* raw, int width, int height)
{
  //这里使用opencv函数
    using namespace cv;
    using namespace std;
    Mat frame(height, width, CV_8UC4, raw);
}
}

上面就是最基础的使用方法了,编译完成就好,在windows里面是dll动态库,在linux和android里面是 so 文件。

3、unity 摄像头

同样,unity里面可以使用动态库的方式来接收rtsp 的画面,同时,也可以使用WebCapTexture 来获取web摄像头, untiy 使用c# 代码

public WebCamTexture webcam;
if (webcam.isPlaying)
{
	Color32[] rawImg = webcam.GetPixels32();
	System.Array.Reverse(rawImg);
	processImage(rawImg, webcam.width, webcam.height);
}
//Runtime
using System.Runtime.InteropServices;

[DllImport("Imagelib", EntryPoint = "processImage")]
public static extern void processImage(Color32[] raw, int width, int height);

以上是使用usb 的摄像头,每一帧都去处理没有必要,切记

4、unity中的传输

unity 中可以使用传输方案,比如接收rtsp 或者 sip GB28181 的视频,都可以使用插件的方式,使用c++做好传输库,在unity里面展现就好。
这个就下一篇再讲了。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1352980.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-14
下一篇 2022-06-14

发表评论

登录后才能评论

评论列表(0条)

保存