当前位置:网站首页>In unity, opencv and QT are used to create a plugin (I)

In unity, opencv and QT are used to create a plugin (I)

2022-06-11 19:51:00 qianbo_ insist

1、unity

unity Is a very good tool , Simple and easy to use , How to be in unity Use in opencv? There are two ways , One is the rgba Transmit past , Create a service receiving , One is to use plug-ins , For those familiar with dynamic libraries , Relatively simple .

2、 Use qt Build dynamic link library

qt Inside, a dynamic link library is built , choice mingw 64
 Insert picture description here
Use qt The advantage is to build a dynamic library and adapt to multiple operating systems at the same time


#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)
{
    
  // Use here opencv function 
    using namespace cv;
    using namespace std;
    Mat frame(height, width, CV_8UC4, raw);
}
}

The above is the most basic use method , Just compile it , stay windows Inside is dll Dynamic library , stay linux and android Inside is so file .

3、unity camera

Again ,unity The dynamic library can be used to receive rtsp The picture of , meanwhile , You can also use WebCapTexture To get web camera , untiy Use c# Code

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);

The above is the use of usb 's camera , There is no need to process every frame , Bear in mind

4、unity Transport in

unity Transmission schemes can be used in , Like receiving rtsp perhaps sip GB28181 In the video , You can use plug-ins , Use c++ Complete the transmission Library , stay unity Just show it inside .
This will be covered in the next article .

原网站

版权声明
本文为[qianbo_ insist]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111948509849.html