资源简介
格雷码图片生成与保存C++实现代码

代码片段和文件信息
#include “CodecGrayCode.h“
#include
#include
#include “csvtools.h“
static unsigned int Nhorz = 10;
static unsigned int Nvert = 6;
#ifndef log2f
#define log2f(x) (log(x)/log(2.0))
#endif
using namespace std;
/*
* The purpose of this function is to convert an unsigned
* binary number to reflected binary Gray code.
*
* The operator >> is shift right. The operator ^ is exclusive or.
* Source: http://en.wikipedia.org/wiki/Gray_code
*/
static unsigned int binaryToGray(unsigned int num) {
return (num >> 1) ^ num;
}
/*
* From Wikipedia: http://en.wikipedia.org/wiki/Gray_code
* The purpose of this function is to convert a reflected binary
* Gray code number to a binary number.
*/
static unsigned grayToBinary(unsigned num unsigned numBits)
{
for (unsigned shift = 1; shift < numBits; shift <<= 1){
num ^= num >> shift;
}
return num;
}
/*
* Function takes the decimal number
* Function takes the Nth bit (1 to 31)
* Return the value of Nth bit from decimal
* Source: http://icfun.blogspot.com/2009/04/get-n-th-bit-value-of-any-integer.html
*/
static int get_bit(int decimal int N){
// Shifting the 1 for N-1 bits
int constant = 1 << (N - 1);// If the bit is set return 1
if (decimal & constant){
return 1;
}
// If the bit is not set return 0
return 0;
}
static inline int powi(int num unsigned int exponent){
// NOT EQUIVALENT TO pow()
if (exponent == 0)
return 1;
float res = num;
for (unsigned int i = 0; i res *= num;
return res;
}
// Encoder
EncoderGrayCode::EncoderGrayCode(unsigned int _screenCols unsigned int _screenRows CodecDir _dir) : Encoder(_screenCols _screenRows _dir){
N = 2;
// Set total pattern number
if (dir & CodecDirHorizontal)
this->N += Nhorz;
if (dir & CodecDirVertical)
this->N += Nvert;
// Encode every pixel column
int NbitsHorz = ceilf(log2f((float)screenCols));
// Number of vertical encoding patterns
int NbitsVert = ceilf(log2f((float)screenRows));
cv::Mat patternOn(1 1 CV_8UC3 cv::Scalar(0));
patternOn.at(0 0) = cv::Vec3b(255 255 255);
patterns.push_back(patternOn);
cv::Mat patternOff(1 1 CV_8UC3 cv::Scalar(0));
patterns.push_back(patternOff);
if (dir & CodecDirHorizontal)
{
// Precompute horizontally encoding patterns
for (unsigned int p = 0; p cv::Mat patternP(1 screenCols CV_8UC3);
// Loop through columns in first row
for (unsigned int j = 0; j unsigned int jGray = binaryToGray(j);
// Amplitude of channels
float amp = get_bit(jGray NbitsHorz - p);
patternP.at(0 j) =
cv::Vec3b(255.0*amp 255.0*amp 255.0*amp);
}
patterns.push_back(patternP);
}
}
if (dir & CodecDirVertical){
// Precompute vertical encoding patterns
for (unsigned int p = 0; p cv::Mat patternP(screenRows 1 CV_8UC3);
// Loop through rows in first column
for (unsigned int i = 0; i
unsigned int
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12915 2019-11-18 17:52 grayCode\0.jpg
文件 12915 2019-11-18 17:52 grayCode\1.jpg
文件 114290 2019-11-18 17:52 grayCode\10.jpg
文件 57458 2019-11-18 17:52 grayCode\11.jpg
文件 12918 2019-11-18 17:52 grayCode\12.jpg
文件 12918 2019-11-18 17:52 grayCode\13.jpg
文件 12923 2019-11-18 17:52 grayCode\14.jpg
文件 12930 2019-11-18 17:52 grayCode\15.jpg
文件 12945 2019-11-18 17:52 grayCode\16.jpg
文件 12975 2019-11-18 17:52 grayCode\17.jpg
文件 13153 2019-11-18 17:52 grayCode\2.jpg
文件 13155 2019-11-18 17:52 grayCode\3.jpg
文件 13395 2019-11-18 17:52 grayCode\4.jpg
文件 13875 2019-11-18 17:52 grayCode\5.jpg
文件 14835 2019-11-18 17:52 grayCode\6.jpg
文件 16755 2019-11-18 17:52 grayCode\7.jpg
文件 31347 2019-11-18 17:52 grayCode\8.jpg
文件 172658 2019-11-18 17:52 grayCode\9.jpg
文件 1326 2019-11-18 16:47 grayCode\Codec.h
文件 5938 2019-11-18 17:00 grayCode\CodecGrayCode.cpp
文件 670 2019-11-18 16:27 grayCode\CodecGrayCode.h
文件 822 2019-11-18 16:42 grayCode\Csvtools.h
文件 11573 2019-11-18 16:46 grayCode\cvtools.cpp
文件 16252928 2019-11-18 17:53 grayCode\grayCode.sdf
文件 1315 2019-11-18 16:47 grayCode\grayCode.sln
..A..H. 29696 2019-11-18 17:53 grayCode\grayCode.v12.suo
文件 7611 2019-11-18 16:47 grayCode\grayCode.vcxproj
文件 1616 2019-11-18 16:47 grayCode\grayCode.vcxproj.filters
文件 2378 2019-11-18 16:48 grayCode\Pstools.cpp
文件 628 2019-11-18 16:42 grayCode\Pstools.h
............此处省略61个文件信息
相关资源
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
评论
共有 条评论