yuv IplImage

1
2
3
4
5
6
7
8
9
10
IplImage *Yuv2IplImage(char *yuv, int imgWidth, int imgHeight)
{
	cv::Mat matYUV(imgHeight * 3 / 2, imgWidth, CV_8UC1, yuv);
	cv::Mat matBGR;
	cv::cvtColor(matYUV, matBGR, cv::COLOR_YUV2BGR_NV12);
 
	IplImage imgTmp = matBGR;
	IplImage *img = cvCloneImage(&imgTmp);
	return img;
}

火狐控件弹出菜单后没反应

如果能改控件程序,比如用FireBreath做的控件,就要使onWindowEvent函数中的WM_PAINT和WM_ERASEBKGND重载返回false。

如果不能改控件程序,试试卸载firefox,再删除文件夹C:\Users\用户名\AppData\Roaming\Mozilla\Firefox,最后重装firefox。同时记住关掉firefox的自动更新。

但有可能重装了也不行,任务管理器中还是两个firefox.exe进程。

所以能改控件程序最完美。

将h264流存为avi文件

使用ffmpeg存为avi和存为mp4在代码上是一样的,ffmpeg可以通过文件名后缀决定视频文件类型,以下是关键代码:

AviWriter.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once
 
class AVFormatContext;
class AVStream;
 
class AviWriter
{
public:
	int createFile(const char* filename);
	int setVideoTrack(const char* sps, int spslen, const char* pps, int ppslen, int width, int hight, int rate);
	int writeVideoSample(char* data, int datasize, bool keyframe);
	void closeFile();
 
private:
	AVFormatContext *m_fc;
	AVStream *m_avStream;
	int m_isHeaderWritten;
};

Read more

获取球机的辅码流

从编程角度讲,球机的辅码流和主码流差别就是uri,如海康的球机主码流如:

rtsp://admin:admin@192.168.1.224/1

则其辅码流为:

rtsp://admin:admin@192.168.1.224/2

那如何获取辅码流呢?

是通过onvif协议登陆球机后,获取profile列表,在列表中选择低分辨率的profile,比如宽小于1800,或者高小于1000的就可认为是辅码流,就可取出对应的uri。

webservice c++

在C++中怎么调用webservice?微软的vs里总是对webservice支持不够,其实最安心的还是用开源的gsoap,现在已经很稳定了。

网上关于使用gsoap的教程一大堆,我只说关于使用中碰到的一个问题:我在客户端已将发送的字符串转码成utf8了,通过gsoap发送过去,服务器端接收到的还是乱码,此时,只要在客户端初始化gsoap时加入:

1
2
3
4
5
struct soap soapCtx;
//注意此时不要再调用soap_init了,在上一句的构造函数中,
//gsoap自己已经调用过soap_init了。
// soap_init(&soapCtx);
soap_set_mode(&soapCtx, SOAP_C_UTFSTRING);

Android jni GetTickCount

1
2
3
4
5
6
unsigned long GetTickCount()
{
	struct timespec ts;
	clock_gettime(CLOCK_MONOTONIC, &ts);
	return (ts.tv_sec * 1000 + ts.tv_nsec / (1000 * 1000));
}

pcap-stdinc.h inline C1189

更换了pcap.h和windows.h的包含顺序后,编译出现如下错误:

warning C4005: 'inline' : macro redefinition
fatal error C1189: #error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.

解决方法,注释掉pcap-stdinc.h里的:

//#define inline __inline

caffe FLAGS_gpu

FLAGS_gpu直接在caffe里找定义是找不到的,它由这句定义:

DEFINE_string(gpu, ...

所以想运行device_query的命令行应该这样输入:

caffe.exe device_query -gpu all