opencv的几个基础函数
来源:互联网 发布:googletts中文语音数据 编辑:程序博客网 时间:2024/06/14 03:29
#include <string.h>
#include "Barcode2D/MaxiCode.h"
static int opencv_entry( int argc, char** argv );
using namespace Barcode2D;
int main(int argc,char *argv[])
{
return opencv_entry(0, NULL);
}
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <string>
#include "MaxiCode_Map.h"
using namespace cv;
using namespace std;
void getMaxiValues(Mat binaryimage, int *maxiValues);
void getCodeWords(int* maxiValues, unsigned char* testCodeWords);
void printMaxiValues(int* maxiValues);
void printCodeWords(unsigned char* testCodeWords);
static int opencv_entry( int argc, char** argv )
{string imageName("./maxicode.result.png"); // by default
if( argc > 1)
{
imageName = argv[1];
}
Mat image, binaryimage;
image = imread(imageName.c_str(), IMREAD_GRAYSCALE); // Read the file
if( image.empty() ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
threshold(image, binaryimage, 150, 255, THRESH_BINARY);
int maxiValues[MAX_BYTE_NUM];
unsigned char testCodeWords[MAX_DATA_LENGTH];
//Step 1:
//Scan the image to get the corresponding data and compare the image and the output information to test whether it is accurate.
getMaxiValues(binaryimage, maxiValues);
printMaxiValues(maxiValues);
//Step 2:
//Get the character array by calculating the data of the integer array.
getCodeWords(maxiValues, testCodeWords);
printCodeWords(testCodeWords);
//Show the original image and the modified image.
namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
namedWindow( "Binary window", WINDOW_AUTOSIZE ); // Create a window for display.
imshow( "Binary window", binaryimage ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
//Scan the image to get MaxiValues.
void getMaxiValues(Mat binaryimage, int *maxiValues)
{
int heght = binaryimage.rows;
int length = binaryimage.cols;
double binaryimageX = length / 30;
double binaryimageY = (heght - binaryimageX * sqrt(3) / 6) / 33;
double binaryimageV = binaryimageY + binaryimageX * sqrt(3) / 6;
int characterId = 0;
int rowId, columnId, maxColumn;
double x, y = binaryimageV / 2;
uchar pixelval;
for(rowId = 0;rowId < MAX_ROW;rowId++, y += binaryimageY)
{
if((rowId%2) == 0)
{
x = binaryimageX/2;
maxColumn = ODD_MAX_COLUMN;
}
else
{
x = binaryimageX;
maxColumn = EVEN_MAX_COLUMN;
}
for(columnId = 0;columnId < maxColumn;columnId++, characterId++, x += binaryimageX)
{
pixelval = binaryimage.at<uchar>(y+0.5, x+0.5);
if(pixelval == 0)
{
maxiValues[characterId] = 1;
}else
{
maxiValues[characterId] = 0;
}
}
if(maxColumn == EVEN_MAX_COLUMN)
{
maxiValues[characterId] = 0;
characterId++;
}
}
}
//Get codewords by calculating the data of maxiValues and MaxiGrid array.
void getCodeWords(int* maxiValues, unsigned char* testCodeWords)
{
unsigned char* codeword = testCodeWords;
memset(codeword, 0, MAX_DATA_LENGTH*sizeof(unsigned char));
for(int index = 0 ;index < MAX_BYTE_NUM;index++)
{
int pixel = maxiValues[index];
int codeindex = MaxiGrid[index];
if(pixel > 0 && codeindex > 0)
{
int byteindex = (codeindex-1)/6;
int bitindex = (codeindex-1)%6;
codeword = testCodeWords + byteindex;
*codeword |= (1 << (5-bitindex));
}
}
}
//Print MaxiValues.
void printMaxiValues(int* maxiValues)
{
for(int id = 0;id < MAX_BYTE_NUM;id++)
{
if(id%ODD_MAX_COLUMN == 0)
printf("\n");
printf("%d ", maxiValues[id]);
}
}
//Print CodeWords.
void printCodeWords(unsigned char* testCodeWords)
{
for(int ida = 0;ida < MAX_DATA_LENGTH;ida++)
{
if(ida%4 == 0)
printf("\n");
printf("0x%x ", testCodeWords[ida]);
}
}
参考:
http://www.learnopencv.com/opencv-threshold-python-cpp/
http://www.cnblogs.com/xianglan/archive/2011/07/30/2122302.html
- opencv的几个基础函数
- Opencv中常用的几个函数
- opencv 用到的几个函数整理cvLine
- opencv画图的几个函数例程
- opencv基本的几个图像处理函数
- opencv几个函数
- 【Python&NLP】nltk的几个基础函数
- opencv的几个图像载入、显示和输出的函数
- openCV 几个位运算函数
- [OpenCV基础] OpenCV中对mixChannels函数的理解
- openCV基础函数【转】
- OpenCV 基础函数
- opencv基础函数代码
- opencv基础函数汇总
- 【Fiddler】几个接函数的基础方法解析
- OpenCV几个函数用法(笔记)
- OpenCV的几个小技巧
- OpenCV的几个小技巧
- is not mapped [from ***]
- 汇编中断知识之INT 1CH
- 蓝牙sdptool browse调用流程
- 微信公众号支付、退费开发
- 连接池模型思想
- opencv的几个基础函数
- linux send与recv函数详解
- IO流的使用
- 关于PopupWindow的showAsDropDown()和showAtLocation()使用方式,popupWindow的各种弹出
- Android Studio引入包
- 用UITextField输入完整汉字或字母再触发textFieldDidChange
- 关于 tomcat 集群中 session 共享的三种方法
- DS18B20
- HTC 瞬移(VRTK)