私はあなたがそれを解決できることを少しは疑問に思います。ネイティブOpenCVをベースにした、単一性のAndroidアプリケーション
私は1つでアンドロイドアプリケーションを作成したいと思います。アプリケーションは、デバイスのカメラを起動し、画面上でそれを表示することから成ります。このために、私はOpenCVに基づくネイティブC++コードをベースにしたいと考えています。
私は生成されたコードを持っていますが、アプリケーションを実行するとシーンが表示されますが、画像は表示されません。また、OpenCVのVideoCapture機能によってAndroid用にうまく使用されないためです。
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#の:私は、コードを添付して私を助けることができるあなたはGitHubの上であなたの全体のコードを主催しているか、あなたはその要旨を作成することができればより良いかもしれない場合
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;
}}
'imgData = new byte [width * height * 4];'なぜ4倍していますか?あなたのカメラは4チャンネルの画像を提供していますか? – zindarod
RGB画像なので、3チャンネルを入れてみましたが失敗しました。だから私は4チャンネルを入れた –
'RGB'は3チャンネルを意味する。あなたのコードが失敗しているのは、何か他の理由によるものです。 @uelordiが示唆するように、Javaネイティブコードで画像をキャプチャし、OpenCVを使用して画像のみを処理してみてください。 – zindarod