我有一个小小的疑问,我希望你能解决它.
我想以统一的方式创建一个Android应用程序.该应用程序包括激活设备的摄像头并在屏幕上查看.为此,我想基于OpenCV的本机C代码.
我有生成的代码,但是当我运行应用程序时,我看到的是场景而不是图像,我觉得这是因为OpenCV的VideoCapture函数我没有很好地使用它.你能帮帮我我附上代码:
C :
__declspec(dllexport) void iniciar(int& widt, int& heigh) {
camera.open(0);
if (!camera.isOpened())
{
return;
}
widt = (int)camera.get(CV_CAP_PROP_FRAME_WIDTH);
heigh = (int)camera.get(CV_CAP_PROP_FRAME_HEIGHT);
trueRect.x = 5;
trueRect.y = 5;
trueRect.width = 100;
trueRect.height = 100;
midX = 1;
midY = 1;
wi = 0;
he = 0;
}
__declspec(dllexport)
void video(unsigned char* arr) {
Mat frame;
Mat resi;
Mat dst;//dst image
camera >> frame;
if (frame.empty()) {
return;
}
flip(frame, dst,1);
//resize(dst, resi, Size(width, height));
cv::cvtColor(dst, dst, COLOR_BGR2RGB);
copy(dst.datastart, dst.dataend, arr);
}
C#:
public class camara : MonoBehaviour {
[DllImport("NativoPrincipio")]
public static extern void video(byte[] img);
[DllImport("NativoPrincipio")]
public static extern void iniciar(ref int widt, ref int heigh);
WebCamTexture back;
Texture2D textura;
byte[] imgData;
int width = 0;
int height = 0;
// Use this for initialization
void Start () {
back = new WebCamTexture();
//GetComponent<Renderer>().material.mainTexture = back;
//back.Play();
iniciar(ref width, ref height);
}
// Update is called once per frame
void Update ()
{
imgData = new byte[width * height * 4];
video(imgData);
textura = new Texture2D(width, height, TextureFormat.RGB24, false);
textura.LoadRawTextureData(imgData);
textura.Apply();
GetComponent<Renderer>().material.mainTexture = textura;
imgData = null;
textura = null;
}}
解决方法:
如果您已经在GitHub上托管了整个代码,或者如果您可以创建一个要点可能会更好.
但是,我认为你的相机框架是空的.
我将尝试列举为什么会发生这种情况.
>首先,opencv视频捕获类camera.open(0)在没有ffmpeg的情况下不起作用(对于Android Native来说不容易交叉编译).
>如果你想在android中使用c中的本机摄像头,你需要使用api 24的最新ndk.
>我看到你正在使用Unity的WebCamTexture类,但几乎可能这个抓取的纹理是空的,因此你会在图像中看到黑屏.
您是否尝试搜索opencv的Unity插件?
我唯一看到的是这个(不是免费的):
https://www.assetstore.unity3d.com/en/#!/content/21088
如果这不起作用,你有没有办法粘贴统一项目的Java代码?因为java中的相机捕获非常容易.
希望这些线索能帮到你.
Ondo izan eta animo.
垂发.
原文地址:https://codeday.me/bug/20190627/1306109.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。