64位编译器下,将指针转换成UINT32,不需要修改编译选项的编码方式
一些严格的64位编译器,将指针转换成UINT32,会报各种丢失精度的错误。
但很显然,有些时候,我们就是需要转换,且并不会真正丢失精度。
此时不需要修改编译选项的编码方式,有些用处了
示例如下:
unsigned int aaa = (unsigned int)(size_t)((void*)0);
size_t是关键!!!
一些严格的64位编译器,将指针转换成UINT32,会报各种丢失精度的错误。
但很显然,有些时候,我们就是需要转换,且并不会真正丢失精度。
此时不需要修改编译选项的编码方式,有些用处了
示例如下:
unsigned int aaa = (unsigned int)(size_t)((void*)0);
size_t是关键!!!
视频帧双缓冲区的第一个版本,仅缓冲视频帧,CSharedCriticalSection是临界区保护类
classCFrameCache{public:
CFrameCache()
: pop_frame_ptr_(nullptr)
, push_frame_ptr_(nullptr)
, width_(0), hight_(0), channels_(0){
}~CFrameCache() {if(pop_frame_ptr_) {delete[] pop_frame_ptr_;
pop_frame_ptr_=nullptr;
}if(push_frame_ptr_){delete[] push_frame_ptr_;
push_frame_ptr_=nullptr;
}
}void push_frame(const char* frame, int width, int hight, intchannels){if(nullptr == frame || width < 0 || hight < 0 || channels < 0) {return;
}
CSharedMutexlock(mutex_);if(push_frame_ptr_ == nullptr &&pop_frame_ptr_==nullptr) {
width_=width;
hight_=hight;
channels_=channels;
pop_frame_ptr_= new char[width_ * hight_ *channels_];
push_frame_ptr_= new char[width_ * hight_ *channels_];
memset(pop_frame_ptr_,0x00, width_ * hight_ *channels_);
memset(push_frame_ptr_,0x00, width_ * hight_ *channels_);
}if((width != width_ || hight_ != hight || channels_ != channels) && push_frame_ptr_ &&pop_frame_ptr_) {
width_=width;
hight_=hight;
channels_=channels;delete[] pop_frame_ptr_;delete[] push_frame_ptr_;
pop_frame_ptr_= new char[width_ * hight_ *channels_];
push_frame_ptr_= new char[width_ * hight_ *channels_];
memset(pop_frame_ptr_,0x00, width_ * hight_ *channels_);
memset(push_frame_ptr_,0x00, width_ * hight_ *channels_);
}
memset(push_frame_ptr_,0x00, width_ * hight_ *channels_);
memcpy(push_frame_ptr_, frame, width_* hight_ *channels_);
}const char*pop_frame(){
CSharedMutexlock(mutex_);
std::swap(push_frame_ptr_, pop_frame_ptr_);returnpop_frame_ptr_;
}intsize(){
CSharedMutexlock(mutex_);return width_ * hight_ *channels_;
}intWidth() {
CSharedMutexlock(mutex_);returnwidth_;
}intHight() {
CSharedMutexlock(mutex_);returnhight_;
}intChannels() {
CSharedMutexlock(mutex_);returnchannels_;
}protected:
CFrameCache(const CFrameCache&rhs){
}
CFrameCache& operator=(const CFrameCache&rhs){return *this;
}private:char*pop_frame_ptr_;char*push_frame_ptr_;intwidth_, hight_, channels_;
CSharedCriticalSection mutex_;
};
视频帧双缓冲区的第二个版本,缓冲视频帧,并允许保存一些视频的附加信息
//带EXIF信息的帧缓冲 template <typename ExifClass> classCFrameCacheWithExif{public:
CFrameCacheWithExif()
: pop_frame_ptr_(nullptr)
, push_frame_ptr_(nullptr)
, width_(0), hight_(0), channels_(0){
}~CFrameCacheWithExif() {if(pop_frame_ptr_) {delete[] pop_frame_ptr_;
pop_frame_ptr_=nullptr;
}if(push_frame_ptr_){delete[] push_frame_ptr_;
push_frame_ptr_=nullptr;
}if(pop_exif_ptr_) {delete[] pop_exif_ptr_;
pop_exif_ptr_=nullptr;
}if(push_exif_ptr_){delete[] push_exif_ptr_;
push_exif_ptr_=nullptr;
}
}void push_frame(const char* frame, const void* exif, int width, int hight, intchannels){if(nullptr == frame || width < 0 || hight < 0 || channels < 0) {return;
}
CSharedMutexlock(mutex_);if(push_frame_ptr_ == nullptr &&pop_frame_ptr_==nullptr) {
width_=width;
hight_=hight;
channels_=channels;
pop_frame_ptr_= new char[width_ * hight_ *channels_];
push_frame_ptr_= new char[width_ * hight_ *channels_];
memset(pop_frame_ptr_,0x00, width_ * hight_ *channels_);
memset(push_frame_ptr_,0x00, width_ * hight_ *channels_);
pop_exif_ptr_= new unsigned char[sizeof(ExifClass)];
push_exif_ptr_= new unsigned char[sizeof(ExifClass)];
memset(pop_exif_ptr_,0x00, sizeof(ExifClass));
memset(push_exif_ptr_,0x00, sizeof(ExifClass));
}if((width != width_ || hight_ != hight || channels_ != channels) && push_frame_ptr_ &&pop_frame_ptr_) {
width_=width;
hight_=hight;
channels_=channels;delete[] pop_frame_ptr_;delete[] push_frame_ptr_;
pop_frame_ptr_= new char[width_ * hight_ *channels_];
push_frame_ptr_= new char[width_ * hight_ *channels_];
memset(pop_frame_ptr_,0x00, width_ * hight_ *channels_);
memset(push_frame_ptr_,0x00, width_ * hight_ *channels_);delete[] pop_exif_ptr_;delete[] push_exif_ptr_;
pop_exif_ptr_= new unsigned char[sizeof(ExifClass)];
push_exif_ptr_= new unsigned char[sizeof(ExifClass)];
memset(pop_exif_ptr_,0x00, sizeof(ExifClass));
memset(push_exif_ptr_,0x00, sizeof(ExifClass));
}
memset(push_frame_ptr_,0x00, width_ * hight_ *channels_);
memcpy(push_frame_ptr_, frame, width_* hight_ *channels_);
memset(push_exif_ptr_,0x00, sizeof(ExifClass));
memcpy(push_exif_ptr_, exif,sizeof(ExifClass));
}const char* pop_frame(void**exif){
CSharedMutexlock(mutex_);
std::swap(push_frame_ptr_, pop_frame_ptr_);
std::swap(push_exif_ptr_, pop_exif_ptr_);if (nullptr !=exif) {*exif =pop_exif_ptr_;
}returnpop_frame_ptr_;
}intsize(){
CSharedMutexlock(mutex_);return width_ * hight_ *channels_;
}intWidth() {
CSharedMutexlock(mutex_);returnwidth_;
}intHight() {
CSharedMutexlock(mutex_);returnhight_;
}intChannels() {
CSharedMutexlock(mutex_);returnchannels_;
}protected:
CFrameCacheWithExif(const CFrameCacheWithExif&rhs){
}
CFrameCacheWithExif& operator=(const CFrameCacheWithExif&rhs){return *this;
}private:char*pop_frame_ptr_;
unsignedchar*pop_exif_ptr_;char*push_frame_ptr_;
unsignedchar*push_exif_ptr_;intwidth_, hight_, channels_;
CSharedCriticalSection mutex_;
};
opencv、numpy中矩阵转置,矩阵内的固定位置相应的坐标变换
编译安卓NDK库时,发现在R15的NDK编译出来的库,总是带了-g选项,导致附带调试,文件过大。
搜索一番后,结论是NDK的文件中有问题:
https://github.com/android/ndk/issues/243
R15版本的android.toolchain.cmake中,并未区分Release与RelWithDebInfo两种情况,直接附带-g选项
这种情况下,如果修改android.toolchain.cmake当然是大动干戈了,想想办法,CMake中的String派上用场了
在工程的CMakeLists.txt中添加如下选项:
再编译时,-g选项就会去除了
配置XFCE4的时钟显示格式,如下1:
%b%d %A, %R:%S
显示结果:
10月09日 星期三,09:50:45
如下2:
[%Y年%b %d日] [%A],第%V周,第%j天
显示结果:
2019年10月09日 星期三,第41周,第282天