赞
踩
提示:海康摄像头的调试
在海康官网 下载 ivms-4200 客户端,并且 摄像头和电脑在一个网段内,
客户端会自动搜索 网段内的 摄像头。
提示:以下是本篇文章正文内容,下面案例可供参考
示例:应下载 设备网络SDK_Linux32 和 播放库SDK_Windows。(如下图)点击跳转
sourceSets {
main {
jniLibs.srcDir 'libs'
}
}
3.更改SDKGuider.java中的文件路径
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
代码如下(示例): 初始化时调用即可
/** * @return login ID * @fn loginNormalDevice * @author lsw8569013 * @brief login on device */ private int loginNormalDevice() { // get instance m_oNetDvrDeviceInfoV30 = new NET_DVR_DEVICEINFO_V30(); if (null == m_oNetDvrDeviceInfoV30) { Log.e(TAG, "HKNetDvrDeviceInfoV30 new is failed!"); return -1; } // call NET_DVR_Login_v30 to login on, port 8000 as default int iLogID = HCNetSDK.getInstance().NET_DVR_Login_V30(ADDRESS, PORT, USER, PSD, m_oNetDvrDeviceInfoV30); if (iLogID < 0) { Log.e(TAG, "NET_DVR_Login is failed!Err:" + HCNetSDK.getInstance().NET_DVR_GetLastError()); return -1; } if (m_oNetDvrDeviceInfoV30.byChanNum > 0) { m_iStartChan = m_oNetDvrDeviceInfoV30.byStartChan; m_iChanNum = m_oNetDvrDeviceInfoV30.byChanNum; } else if (m_oNetDvrDeviceInfoV30.byIPChanNum > 0) { m_iStartChan = m_oNetDvrDeviceInfoV30.byStartDChan; m_iChanNum = m_oNetDvrDeviceInfoV30.byIPChanNum + m_oNetDvrDeviceInfoV30.byHighDChanNum * 256; } Log.e(TAG, "NET_DVR_Login is Successful!"); return iLogID; }
代码如下(示例):
/** * 摄像头抓图 * @param view */ public void getPIC(View view) { String path = Environment.getExternalStorageDirectory()+"/抓图.jpg"; NET_DVR_JPEGPARA jpegpara = new NET_DVR_JPEGPARA(); jpegpara.wPicSize = 2; jpegpara.wPicQuality = 2; HCNetSDK NetSdk = HCNetSDK.getInstance(); boolean b = NetSdk.NET_DVR_CaptureJPEGPicture(m_iLogID, 1, jpegpara, path); if(b){ LogUtil.e("抓图成功"); ImageView iv_showCAMERAPic = findViewById(R.id.iv_showCAMERAPic); iv_showCAMERAPic.setImageBitmap(BitmapFactory.decodeFile(path)); }else{ LogUtil.e("抓图error"+NetSdk.NET_DVR_GetLastError() ) ; } }
代码如下(示例):
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback { private int m_iPreviewHandle = -1; @Override public void surfaceCreated(@NonNull SurfaceHolder holder) { m_surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); if (-1 == m_iPreviewHandle) { return; } Surface surface = holder.getSurface(); if (surface.isValid()) { if (-1 == SDKGuider.g_sdkGuider.m_comPreviewGuider.RealPlaySurfaceChanged_jni(m_iPreviewHandle, 0, holder)) Toast.makeText(MainActivity.this,"NET_DVR_PlayBackSurfaceChanged"+ SDKGuider.g_sdkGuider.GetLastError_jni(),Toast.LENGTH_SHORT).show(); } } @Override public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) { } @Override public void surfaceDestroyed(@NonNull SurfaceHolder holder) { if (-1 == m_iPreviewHandle) { return; } if (holder.getSurface().isValid()) { if (-1 == SDKGuider.g_sdkGuider.m_comPreviewGuider.RealPlaySurfaceChanged_jni(m_iPreviewHandle, 0, null)) { Toast.makeText(MainActivity.this,"NET_DVR_RealPlaySurfaceChanged"+ SDKGuider.g_sdkGuider.GetLastError_jni(),Toast.LENGTH_SHORT).show(); } } } }
添加“开始预览”按钮,并添加点击事件
private SurfaceView m_surfaceView = null; private Button start; private SurfaceHolder holder; m_surfaceView = findViewById(R.id.Surface_Preview_Play); holder = m_surfaceView.getHolder(); start = findViewById(R.id.button_preview_start); start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { m_surfaceView.getHolder().addCallback(MainActivity.this); m_surfaceView.setZOrderOnTop(true); SDKGuider.g_sdkGuider.m_comPreviewGuider.RealPlaySurfaceChanged_jni(m_iPreviewHandle, 0, holder); NET_DVR_PREVIEWINFO struPlayInfo = new NET_DVR_PREVIEWINFO(); struPlayInfo.lChannel = 1; struPlayInfo.dwStreamType = 0; struPlayInfo.bBlocked = 1; struPlayInfo.hHwnd = m_surfaceView.getHolder(); m_iPreviewHandle = SDKGuider.g_sdkGuider.m_comPreviewGuider.RealPlay_V40_jni(0,struPlayInfo, null); if (m_iPreviewHandle < 0) { Toast.makeText(MainActivity.this,"NET_DVR_RealPlay_V40 fail, Err:"+ SDKGuider.g_sdkGuider.GetLastError_jni(),Toast.LENGTH_SHORT).show(); return; } Toast.makeText(MainActivity.this,"NET_DVR_RealPlay_V40 Succ " ,Toast.LENGTH_SHORT).show(); } });
添加“停止预览”按钮,并添加点击事件
private Button stop;
stop = findViewById(R.id.button_stop);
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!SDKGuider.g_sdkGuider.m_comPreviewGuider.RealPlay_Stop_jni(m_iPreviewHandle))
{
Toast.makeText(getContext(),"摄像头停止预览失败" + m_iPreviewHandle + " 错误代码:" + SDKGuider.g_sdkGuider.GetLastError_jni(),Toast.LENGTH_SHORT).show();
return;
}
m_iPreviewHandle = -1;
}
});
退出时,释放SDK资源
if (HCNetSDKJNAInstance.getInstance().NET_DVR_Cleanup()){
Toast.makeText(getContext(), "摄像机SDK释放成功", Toast.LENGTH_SHORT).show();
}
创作不易,各位看官老爷多多支持!~
提示:好了本次技术交流就在这里结束啦!以上方法本人亲测有效坑还是挺多的 像传统的通过对二进制数组解码,可以得到bitma抓拍这种方式延迟久,而且内存占据很大,我们抓拍的方式是本人亲测最快的一种了,当然像sdk初始化,预览这些官网里都是有源代码的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。