由于项目需要调取海康的网络摄像头,而使用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);
//