Linux下Python调用海康sdk显示网络摄像头

本文介绍了如何在Ubuntu 18.04.2上使用Python调用海康网络摄像头,避免高延迟问题。通过安装opencv、codeblocks和swig,结合海康SDK,详细讲解了生成接口文件、编译动态链接库以及测试过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于项目需要调取海康的网络摄像头,而使用opencv的话延迟比较高,所以通过编译海康的sdk来实现。

操作系统:Ubuntu server 18.04.2

opencv版本:3.4.6

codeblocks版本:17.12

需要的一些包我会放在Google云盘 https://drive.google.com/drive/folders/1b61Wq2SovUpBoCS_5yh4TolVsPITjNrn?usp=sharing

一 安装opencv

opencv本人安装的比较早,记不得步骤了,后面如果有需要的话会补上。

二 安装codeblocks和swig

这步也记不得了。

三 使用swig生成接口文件

1. 下载opencv-swig接口文件

2. 新建一个文件夹(比如 hksdk),将将接口文件lib文件夹下的文件与下面三个源文件放入

//HKIPcamera.cpp
#include <opencv2/opencv.hpp>
#include <iostream>
#include <time.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include "HCNetSDK.h"
#include "LinuxPlayM4.h"
#include <unistd.h>
#include <pthread.h>


#define USECOLOR 1
#define WINAPI


using namespace cv;
using namespace std;


//--------------------------------------------
int iPicNum = 0;//Set channel NO.
LONG nPort = -1;
HWND hWnd = NULL;
pthread_mutex_t g_cs_frameList;
list<Mat> g_frameList;
LONG lUserID;
NET_DVR_DEVICEINFO_V30 struDeviceInfo;
LONG lRealPlayHandle = -1;


void yv12toYUV(char *outYuv, char *inYv12, int width, int height, int widthStep)
{
int col, row;
unsigned int Y, U, V;
int tmp;
int idx;


//printf("widthStep=%d.\n",widthStep);


for (row = 0; row<height; row++)
{
idx = row * widthStep;
int rowptr = row*width;


for (col = 0; col<width; col++)
{
//int colhalf=col>>1;
tmp = (row / 2)*(width / 2) + (col / 2);
//         if((row==1)&&( col>=1400 &&col<=1600))
//         {
//          printf("col=%d,row=%d,width=%d,tmp=%d.\n",col,row,width,tmp);
//          printf("row*width+col=%d,width*height+width*height/4+tmp=%d,width*height+tmp=%d.\n",row*width+col,width*height+width*height/4+tmp,width*height+tmp);
//         }
Y = (unsigned int)inYv12[row*width + col];
U = (unsigned int)inYv12[width*height + width*height / 4 + tmp];
V = (unsigned int)inYv12[width*height + tmp];
//         if ((col==200))
//         {
//         printf("col=%d,row=%d,width=%d,tmp=%d.\n",col,row,width,tmp);
//      
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值