从视频文件中使用的OpenCV与本土code C阅读框++ [英] Reading frames from video file using openCV and Native code C++
问题描述
我想编写一个应用程序,获取视频的所有帧和操纵他们,我发现oout,要提取物对Android的框架最好的办法是使用OpenCV的库。
我在使用接收的视频路径,并可以抓住框架出来的VideoCapture对象样本code看见,所以我写了下面code,但capture.open()doen't真正开放视频文件,在capture.isOpen()始终是假的。
来源$ C $ C:
的#include< jni.h>
// OpenCV的
#包括< opencv2 /一下HighGUI / highgui.hpp>
#包括< opencv2 /视频/ background_segm.hpp>
#包括< opencv2 /核心/ mat.hpp>
//C
#包括< stdio.h中>
#包括< string.h中>
// C ++
#包括<的iostream>
#包括< sstream>
//机器人
#包括<安卓/ log.h>
//#定义LOGI(TAG,INFO)__android_log_print(ANDROID_LOG_INFO,信息,__ VA_ARGS__)
使用命名空间的简历;
为externC{
JNIEXPORT无效JNICALL Java_com_example_nativeopencvcheck_MainActivity_processVideo(JNIEnv的* ENV,
jobject thsObj,的jstring文件名){
为const char * fileNameNative;
jboolean isCopy;
fileNameNative = ENV-> GetStringUTFChars(文件名,和放大器; isCopy);
//创建捕获对象
__android_log_print(ANDROID_LOG_ERROR,From_Native
试图打开文件:%s,fileNameNative);
VideoCapture捕获(fileNameNative);
capture.open(fileNameNative);
如果(!capture.isOpened()){// !!!!!!总是关!!!!!
__android_log_write(ANDROID_LOG_ERROR,From_Native
捕捉不开闭..);
出口(EXIT_FAILURE);
}
太IplImage的;
capture.retrieve(IplImage结构,0);
如果(iplimage.size大于0){
JCLASS CLS = ENV->的findClass(COM /例子/ opencvframesext / MainActivity);
如果(CLS == 0){
返回;
}
jmethodID javamethod = ENV->的GetMethodID(CLS,getCurrentFrameFromNative,()V);
如果(javamethod == 0){
// LOGI(From_Native,的GetMethodID错误);
返回;
}
jobject OBJ; // 去做
ENV-> CallVoidMethod(OBJ,javamethod);
返回;
}
/ *布尔gotFrame = capture.read(垫);
而(gotFrame){
mats.addref(垫);
capture.read(垫);
} * /
//删除捕获对象
capture.release();
}
}
是啊,这不会工作,很遗憾。
有没有ffmpeg的后端VideoCapture在Android上。
I'm trying to write an app that gets all the frames of a video and manipulating them, I found oout that the best way to extract frames on Android is using OpenCv lib.
I saw in the sample code that uses VideoCapture object that receives the video path and can grab frames out of it, so I wrote the following code but the capture.open() doen't really open the video file, the capture.isOpen() is always false.
Source code:
#include <jni.h>
//opencv
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/core/mat.hpp>
//C
#include <stdio.h>
#include <string.h>
//C++
#include <iostream>
#include <sstream>
//Android
#include <android/log.h>
//#define LOGI(TAG,INFO) __android_log_print(ANDROID_LOG_INFO,INFO,__VA_ARGS__)
using namespace cv;
extern "C" {
JNIEXPORT void JNICALL Java_com_example_nativeopencvcheck_MainActivity_processVideo(JNIEnv* env,
jobject thsObj,jstring fileName) {
const char * fileNameNative;
jboolean isCopy;
fileNameNative = env->GetStringUTFChars(fileName, &isCopy);
//create the capture object
__android_log_print(ANDROID_LOG_ERROR, "From_Native",
"trying to open file: %s", fileNameNative);
VideoCapture capture(fileNameNative);
capture.open(fileNameNative);
if (!capture.isOpened()) { //!!!!!! ALWAYS CLOSED !!!!!
__android_log_write(ANDROID_LOG_ERROR, "From_Native",
"capture isn't open. closing..");
exit( EXIT_FAILURE);
}
Mat iplimage;
capture.retrieve(iplimage,0);
if (iplimage.size > 0) {
jclass cls = env->FindClass( "com/example/opencvframesext/MainActivity");
if (cls == 0) {
return;
}
jmethodID javamethod = env->GetMethodID(cls, "getCurrentFrameFromNative", "()V");
if (javamethod == 0) {
// LOGI("From_Native","GetMethodID error");
return;
}
jobject obj; // TODO
env->CallVoidMethod(obj, javamethod);
return;
}
/*bool gotFrame = capture.read(mat);
while (gotFrame) {
mats.addref(mat);
capture.read(mat);
}*/
//delete capture object
capture.release();
}
}
yea, that wont work, unfortunately.
there's no ffmpeg backend for VideoCapture on android.
这篇关于从视频文件中使用的OpenCV与本土code C阅读框++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!