资源简介
利用opencv打开网络摄像头,并可以实时编码,编码后的数据保存在本地。
(win7+opencv3.0+海康威视)
代码片段和文件信息
#include
#include
#include
#include “Windows.h“
#include “HCNetSDK.h“
#include “plaympeg4.h“
#include
#include “cv.h“
#include “highgui.h“
#include
#include “stdafx.h“
#include “stdint.h“
#include “opencv2/highgui/highgui.hpp“
#include “opencv2/imgproc/imgproc.hpp“
#include
#include
using namespace cv;
using namespace std;
extern “C“
{
#include “x264.h“
#include “x264_config.h“
};
LONG nPort = -1;
char filename[100];
volatile int gbHandling = 3;
int ct = 0;
int w = 640;
int h = 480;
int yuv_bufLen = w * h * 3 / 2;
unsigned char* pYuvBuf = new unsigned char[yuv_bufLen];
FILE* pFileOut = fopen(“result.yuv“ “w+“);
Mat dst;
int MyYuvtoH264(int width int height string filename)
{
int fps = 15;
size_t yuv_size = width * height * 3 / 2;
x264_t *encoder;
x264_picture_t pic_in pic_out;
uint8_t *yuv_buffer;
x264_param_t param;
x264_param_default_preset(¶m “veryfast“ “zerolatency“);
param.i_threads = 1;
param.i_width = width;
param.i_height = height;
param.i_fps_num = fps;
param.i_fps_den = 1;
param.i_keyint_max = 25;
param.b_intra_refresh = 1;
param.b_annexb = 1;
x264_param_apply_profile(¶m “baseline“);
encoder = x264_encoder_open(¶m);
x264_picture_alloc(&pic_in X264_CSP_I420 width height);
yuv_buffer = (uint8_t*)malloc(yuv_size);
pic_in.img.plane[0] = yuv_buffer;
pic_in.img.plane[1] = pic_in.img.plane[0] + width * height;
pic_in.img.plane[2] = pic_in.img.plane[1] + width * height / 4;
int64_t i_pts = 0;
x264_nal_t *nals;
int nnal;
FILE *inf = fopen(filename.c_str() “rb“);
FILE *outf = fopen(“C:/Users/Administrator/Desktop/test.h264“ “wb“);
if (NULL == inf)
{
return -1;
}
while (fread(yuv_buffer 1 yuv_size inf) > 0)
{
pic_in.i_pts = i_pts++;
x264_encoder_encode(encoder &nals &nnal &pic_in &pic_out);
x264_nal_t *nal;
for (nal = nals; nal < nals + nnal; nal++)
{
fwrite(nal->p_payload 1 nal->i_payload outf);
}
}
x264_encoder_close(encoder);
fclose(inf);
fclose(outf);
free(yuv_buffer);
return 0;
}
//解码回调 视频为YUV数据(YV12),音频为PCM数据
void CALLBACK DecCBFun(long nPort char * pBuf long nSize frame_INFO * pframeInfo long nReserved1 long nReserved2)
{
if (gbHandling)
{
gbHandling--;
return;
}
long lframeType = pframeInfo->nType;
if (lframeType == T_YV12)
{
Mat pImg(pframeInfo->nHeight pframeInfo->nWidth CV_8UC3);
Mat src(pframeInfo->nHeight + pframeInfo->nHeight / 2 pframeInfo->nWidth CV_8UC1 pBuf);
cvtColor(src pImg CV_YUV2BGR_YV12);
int resize_height = 640;
int resize_width = 480;
resize(pImg dst cv::Size(resize_height resize_width) 0 0 INTER_LINEAR);
ct++;
cout << “ct为:“ << ct << endl;
cv::Mat yuvImg;
cv::cvtColor(dst yuvImg CV_BGR2YUV_I420);
memcpy(pYuvBuf yuvImg.data yuv_bufLen*sizeof(unsigned char));
fwrit
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 415744 2017-08-02 15:47 X264-encode 3\Debug\AnalyzeData.dll
文件 428544 2017-08-02 15:47 X264-encode 3\Debug\AudioIntercom.dll
文件 146432 2017-08-02 15:47 X264-encode 3\Debug\AudioRender.dll
文件 463872 2017-08-02 15:57 X264-encode 3\Debug\HCAlarm.dll
文件 1144320 2017-08-02 15:55 X264-encode 3\Debug\HCCore.dll
文件 814592 2017-08-02 15:57 X264-encode 3\Debug\HCCoreDevCfg.dll
文件 612864 2017-08-02 15:58 X264-encode 3\Debug\HCDisplay.dll
文件 1026560 2017-08-02 15:58 X264-encode 3\Debug\HCGeneralCfgMgr.dll
文件 750592 2017-08-02 15:58 X264-encode 3\Debug\HCIndustry.dll
文件 665600 2017-08-02 15:59 X264-encode 3\Debug\HCNetSDK.dll
文件 415744 2017-08-02 15:47 X264-encode 3\Debug\HCNetSDKCom\AnalyzeData.dll
文件 428544 2017-08-02 15:47 X264-encode 3\Debug\HCNetSDKCom\AudioIntercom.dll
文件 463872 2017-08-02 15:57 X264-encode 3\Debug\HCNetSDKCom\HCAlarm.dll
文件 13908 2017-08-02 15:57 X264-encode 3\Debug\HCNetSDKCom\HCAlarm.lib
文件 814592 2017-08-02 15:57 X264-encode 3\Debug\HCNetSDKCom\HCCoreDevCfg.dll
文件 612864 2017-08-02 15:58 X264-encode 3\Debug\HCNetSDKCom\HCDisplay.dll
文件 1026560 2017-08-02 15:58 X264-encode 3\Debug\HCNetSDKCom\HCGeneralCfgMgr.dll
文件 48542 2017-08-02 15:58 X264-encode 3\Debug\HCNetSDKCom\HCGeneralCfgMgr.lib
文件 750592 2017-08-02 15:58 X264-encode 3\Debug\HCNetSDKCom\HCIndustry.dll
文件 418816 2017-08-02 15:58 X264-encode 3\Debug\HCNetSDKCom\HCPlayBack.dll
文件 617472 2017-08-02 15:58 X264-encode 3\Debug\HCNetSDKCom\HCPreview.dll
文件 37192 2017-08-02 15:57 X264-encode 3\Debug\HCNetSDKCom\HCPreview.lib
文件 600576 2017-08-02 15:57 X264-encode 3\Debug\HCNetSDKCom\HCVoiceTalk.dll
文件 978432 2017-08-02 15:47 X264-encode 3\Debug\HCNetSDKCom\libiconv2.dll
文件 655872 2017-08-02 15:47 X264-encode 3\Debug\HCNetSDKCom\msvcr90.dll
文件 427008 2017-08-02 15:47 X264-encode 3\Debug\HCNetSDKCom\OpenAL32.dll
文件 410112 2017-08-02 15:47 X264-encode 3\Debug\HCNetSDKCom\StreamTransClient.dll
文件 653312 2017-08-02 15:47 X264-encode 3\Debug\HCNetSDKCom\SystemTransform.dll
文件 418816 2017-08-02 15:58 X264-encode 3\Debug\HCPlayBack.dll
文件 617472 2017-08-02 15:58 X264-encode 3\Debug\HCPreview.dll
............此处省略270个文件信息
相关资源
- Learning_OpenCV_3.pdf
- 基于opencv车牌识别源码
- ippicv_2017u3_lnx_intel64_20170822.tgz包
- opencv4.1_x86.rar
- opencv for qt5.8
- OpenCV两种方法显示中文
- opencv2.2.0版本
- 最经典的开源车牌识别代码 OPENCV
- 《学习OpenCV(中文版)》-于仕琪
- opencv打开图片并显示在Qt界面上
- opencv1.0.zip
- OpenCV3+Qt5视频处理GUI程序
- Opencv2.0.0
- 识别出表盘的指针刻度-opencv
- opencv4.0.1+contrib+vs2017编译x64x86完全版本
- opencv论文合集2
- opencv3编译需要的opencv_ffmpeg_64.dll
- OpenCVTest
- 编译好的OpenCV3.4.2+Qt5.9+Contrib版
- 基于OPENCV的运动估计-块匹配,根据锚
- opencv 图片处理,分割字符
- opencv4.1+contrib vs2017编译 64位版
- 帧差法实现前景背景分离
- opencv分封装函数到dll
- opencv3.2 + contrib3.2完整编译
- vs2017+OpenCV3.43中值滤波函数使用例程
- opencv3.4.1 32位 Debug版本 x86VS2017编译
- 基于opencv的数字识别
- vc车牌识别程序源代码
- opencv1.1pre1版本
评论
共有 条评论