opencv实时视频帧在android中没有显示sobel输出
16lz
2021-01-22
I am new to opencv. I want to apply sobel filter on real time video using opencv in android but i am failed in doing so. when i use the built-in function of sobel in opencv it gives me the white blank screen.I have searched a lot but didn't find my error..
我是opencv的新手。我想在android中使用opencv在实时视频上应用sobel滤镜,但我没有这样做。当我在opencv中使用sobel的内置功能时,它给了我白色的空白屏幕。我搜索了很多,但没有找到我的错误..
package com.example.bismanawaz.opencvpractice;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceView;
import android.view.WindowManager;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2{
private CameraBridgeViewBase mOpenCvCameraView;
private Mat sobell;
public static final int CV_8UC1=0;
private static final String TAG ="OpenCV" ;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
public void onResume()
{
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_7, this, mLoaderCallback);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloOpenCvView);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
}
@Override
public void onPause()
{
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* This method is invoked when camera preview has started. After this method is invoked
* the frames will start to be delivered to client via the onCameraFrame() callback.
*
* @param width - the width of the frames that will be delivered
* @param height - the height of the frames that will be delivered
*/
@Override
public void onCameraViewStarted(int width, int height) {
sobell = new Mat();
}
/**
* This method is invoked when camera preview has been stopped for some reason.
* No frames will be delivered via onCameraFrame() callback after this method is called.
*/
@Override
public void onCameraViewStopped() {
}
/**
* This method is invoked when delivery of the frame needs to be done.
* The returned values - is a modified frame which needs to be displayed on the screen.
*
* @param inputFrame
*/
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Imgproc.Sobel(inputFrame.gray(),sobell,CV_8UC1,1,1,3);
return sobell;
}
}
1 个解决方案
#1
0
This is my method which is doing Sobel.
这是我做索贝尔的方法。
public static Mat FindSobelEdges(Mat mat) {
Imgproc.Sobel(mat, mat, CvType.CV_8UC1, 1, 1);
return mat;
}
I think your problem is wrong parameters. Pls check the Imgproc.Sobel doc:
我认为你的问题是错误的参数。请检查Imgproc.Sobel文档:
Imgproc.Sobel
更多相关文章
- 错误:未使用的导入语句 - 导入android.widget.AdapterView.OnItem
- Android的Intel XDK构建错误
- Android Studio错误“AppCompat不支持主题”[重复]
- ubuntu (16.04) server 英文原版 添加中文语言支持 消除java 程
- 错误:警告:无法从javaldx读取路径
- Java错误:线程“main”中的异常java.lang.ArrayIndexOutOfBoundsE
- 不幸的是,在声明按钮时,模拟器中出现了错误
- 当我运行.jar时,在java.library中会得到一个“No lwjgl”。路线”
- 导入证书后的Java Keytool错误,“Keytool error: Java .io。FileN