AR多标签识别程序2
来源:互联网 发布:linux中查看文件内容 编辑:程序博客网 时间:2024/06/05 03:15
1 Basic.h 文件部分
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*函数原型声明*/
//获取空调的温度相关信息
char *getAirInfo();
char *getHotChannelInfo();
char *getColdChannelInfo();
char *getCabinetInfo();
char* getPDUInfo();
char *getShortColdChannelInfo();
//产生一个指定区间的浮点数,小数点保留一位
float generateTemp(int lowTemperature, int highTemperature);
int generateInteger(int lowInt, int highInt);
2 GLFont.h部分
// GLFont.h: interface for the CGLFont class.
#if !defined(AFX_GLFONT_H__88F1F000_50F5_452A_B95E_60ED83712FA5__INCLUDED_)
#define AFX_GLFONT_H__88F1F000_50F5_452A_B95E_60ED83712FA5__INCLUDED_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#ifndef __APPLE__
# ifdef _WIN32
# include <windows.h>
# endif
# include <GL/glut.h>
#else
# include <GLUT/glut.h>
#endif
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
void c3dtext(LPCTSTR str, HFONT hFont, float z);
void Printfc3d(LPCTSTR strText, HFONT hFont, float z);
void draw3dtextWithCloseLight(LPCTSTR str, HFONT hFont, float cDepth, float dXoffset, float dYoffset, float dZoffset, float dXscale, float dYscale, float dZscale,
float dXrotate, float dYrotate, float dZrotate);
void draw3dtextIgnoreLight(LPCTSTR strText, HFONT hFont, float cDepth, float dXoffset, float dYoffset, float dZoffset, float dXscale, float dYscale, float dZscale,
float dXrotate, float dYrotate, float dZrotate);
#endif
3 BasicInfo.c
/*
动态获取获取各种设备信息
*/
#include "BasicInfo.h"
/*
获取空调信息
*/
char *getAirInfo(){
//给空调信息分配100个字节
char *airInfoStr=(char *)malloc(sizeof(char)*100);
if (airInfoStr != NULL){
strcpy(airInfoStr,"名称:空调\n温度:");
char buf[10];
float temperature = generateTemp(10, 40);
//snprintf(buf, sizeof(buf)-1, "%5.1f ℃\n", temperature);
sprintf(buf,"%5.1f ℃\n", temperature);
strcat(airInfoStr, buf);
return airInfoStr;
}else{
printf("airInfoStr 内存分配失败\n");
exit(-1);
}
}
/*
获取热通道信息
*/
char *getHotChannelInfo(){
char *channelInfoStr;
channelInfoStr = (char *)malloc(sizeof(char)* 200);
if (channelInfoStr != NULL){
int idleLocationCnt = generateInteger(10, 40);
sprintf(channelInfoStr, "名称:热通道\n空闲位置数量 : %d \n", idleLocationCnt);
return channelInfoStr;
}
else{
printf("channelInfoStr 内存分配失败\n");
exit(-1);
}
}
/*
获取冷通道消息
*/
char *getColdChannelInfo(){
char *channelInfoStr;
channelInfoStr = (char *)malloc(sizeof(char)* 200);
if (channelInfoStr != NULL){
//strcpy(channelInfoStr, "名称:冷通道\n空闲位置数量:");
//char buf[50];
int idleLocationCnt = generateInteger(0, 40);
sprintf(channelInfoStr, "名称:冷通道\n空闲位置数量:%3d个\n", idleLocationCnt);
return channelInfoStr;
}
else{
printf("channelInfoStr 内存分配失败\n");
exit(-1);
}
}
/*
获取机柜信息
*/
char *getCabinetInfo(){
char *cabinetInfoStr=(char *)malloc(sizeof(char)* 350);
//cabinetInfoStr = (char *)malloc(sizeof(char)* 350);
if (cabinetInfoStr != NULL){
strcpy(cabinetInfoStr,"名称:机柜\n");
char buf[300];
float frontDoorUpTemp = generateTemp(20, 40);
float frontDoorBottomTemp = generateTemp(20,40);
float backDoorUpTemp = generateTemp(20, 40);
float backDoorBottomTemp = generateTemp(20,40);
int frontDoorUpHumidity = generateInteger(50, 70);
int frontDoorBottomHumidity = generateInteger(50, 70);
int backDoorUpHumidity = generateInteger(50, 70);
int backDoorBottomHUmidity = generateInteger(50, 70);
/*
snprintf(buf,sizeof(buf)-1,"前门上部温度:%5.1f ℃\n\
前门上部湿度:%d\%\n\
前门底部温度:%5.1f ℃\n\
前门底部湿度:%d %%\n\
后门上部温度:%5.1f ℃\n\
后门上部湿度:%d %%\n\
后门底部温度:%5.1f ℃\n\
后门底部湿度:%d %%\n",frontDoorUpTemp,frontDoorUpHumidity,frontDoorBottomTemp,frontDoorBottomHumidity,
backDoorUpTemp,backDoorUpHumidity,backDoorBottomTemp,backDoorBottomHUmidity);
*/
sprintf(buf, "前门上部温度:%5.1f℃\n前门上部湿度:%d%%\n前门底部温度:%5.1f℃\n前门底部湿度:%d%%\n后门上部温度:%5.1f℃\n后门上部湿度:%d%%\n后门底部温度:%5.1f℃\n\
后门底部湿度:%d %%\n", frontDoorUpTemp, frontDoorUpHumidity, frontDoorBottomTemp, frontDoorBottomHumidity,
backDoorUpTemp, backDoorUpHumidity, backDoorBottomTemp, backDoorBottomHUmidity);
strcat(cabinetInfoStr,buf);
return cabinetInfoStr;
}
else{
printf("cabinetInfoStr 分配失败\n");
exit(-1);
}
}
/*
获取pdu信息
*/
char* getPDUInfo(){
char *pduInfoStr;
pduInfoStr = (char*)malloc(sizeof(char)* 300);
if (pduInfoStr != NULL){
strcpy(pduInfoStr,"名称:PDU\n");
float temp = generateTemp(20, 40);
int voltage = generateInteger(210, 240);
int eCurrent = generateInteger(0, 15);
int humidity = generateInteger(50, 70);
int activePower = generateInteger(70, 100);
char buf[150];
/*snprintf(buf,sizeof(buf)-1,"温度:%5.1f℃\n\
湿度:%d%%\n\
电压:%dV\n\
电流:%dA\n\
有功功率:%dW",temp,humidity,voltage,eCurrent,activePower);*/
sprintf(buf, "温度:%5.1f℃\n湿度:%d%%\n电压:%dV\n电流:%dA\n有功功率:%dW", temp, humidity, voltage, eCurrent, activePower);
strcat(pduInfoStr,buf);
return pduInfoStr;
}else{
printf("pduInfoStr 内存分配失败\n");
exit(-1);
}
}
char *getShortColdChannelInfo(){
char *shortColdChannelInfo;
shortColdChannelInfo = (char*)malloc(sizeof(char)* 300);
if (shortColdChannelInfo != NULL){
strcpy(shortColdChannelInfo,"名称:短冷通道\n位置1:机柜B02\n位置2:机柜A04\n\
位置3:布线机柜B\n位置4:机柜A02\n位置5:机柜A01\n位置6:机柜A03位置7:机柜A05\n\
位置8:B列行间空调\n位置9:配电柜\n位置10:A列行间空调\n位置11:布线机柜A\n位置12:UPS柜\n\
位置13:机柜B01\n位置14:机柜B03");
return shortColdChannelInfo;
}
else{
printf("shortColdChannelInfo内存分配失败\n");
exit(-1);
}
}
/*随机产生一个温度值
lowTemperatur 指定最低温度
highTemperature 指定最高温度
*/
float generateTemp(int lowTemperature,int highTemperature){
int range = highTemperature - lowTemperature;
float randF = (rand() % (range * 10)) / 10.0;
return (lowTemperature + randF);
}
/*
随机产生一个整数,用来表示通道里面的空闲数量
lowNum:产生的最小整数
highNum:产生的最大整数
*/
int generateInteger(int lowInt,int highInt){
int range = highInt - lowInt;
int rangeInt = rand()%range;
return lowInt + rangeInt;
}
4 GLFont3D.c
#include "GLFont.h"
void c3dtext(LPCTSTR str, HFONT hFont, float z)
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
Printfc3d(TEXT(str), hFont, z);
glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
}
void Printfc3d(LPCTSTR strText, HFONT hFont, float z)
{
HDC hdc = wglGetCurrentDC();
HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
UCHAR * pChar = (UCHAR*)strText/*.GetBuffer(strText.GetLength())*/;
int nListNum;
DWORD dwChar;
GLYPHMETRICSFLOAT pgmf[1];
glPushMatrix();
float m_dXOffset = -1.0;
float m_dYOffset = 1.0;
float m_dZOffset = 2.0;
float m_dXScale = 0.10;
float m_dYScale = 0.10;
float m_dZScale = 0.10;
float m_dXRotate = -90.0;
float m_dYRotate = 0.0;
float m_dZRotate = 0.0;
glTranslatef(m_dXOffset, m_dYOffset, m_dZOffset);
//glScalef(1000.0, 1000.0, 10000.0);
//Scale
glScaled(m_dXScale, m_dYScale, m_dZScale);
//Rotate around X-axis
glRotated(m_dXRotate, 1.0, 0.0, 0.0);
//Rotate around Y-axis
glRotated(m_dYRotate, 0.0, 1.0, 0.0);
//Rotate around Z-axis
glRotated(m_dZRotate, 0.0, 0.0, 1.0);
glColor3f(0.0, 1.0, 1.0);
for (int i = 0; i < _tcslen(strText)/*strText.GetLength()*/; i++)
{
if (IsDBCSLeadByte((BYTE)pChar[i]))
{
dwChar = (DWORD)((pChar[i] << 8) | pChar[i + 1]);
i++;
}
else dwChar = pChar[i];
nListNum = glGenLists(1);
wglUseFontOutlines(hdc,
dwChar,
1,
nListNum,
0.0f,
z,
WGL_FONT_POLYGONS, //WGL_FONT_POLYGONS
pgmf
);
glCallList(nListNum);
glDeleteLists(nListNum, 1);
}
//restore the original angle around Z-axis
glRotated(-1.0f * m_dZRotate, 0.0, 0.0, 1.0);
//restore the original angle around Y-axis
glRotated(-1.0f * m_dYRotate, 0.0, 1.0, 0.0);
//restore the original scale
glScaled(1.0 / m_dXScale, 1.0 / m_dYScale, 1.0 / m_dZScale);
//restore the original angle around X-axis
glRotated(-1.0f * m_dXRotate, 1.0, 0.0, 0.0);
glTranslated(-m_dXOffset, -m_dYOffset, -m_dZOffset);
glPopMatrix();
//strText.ReleaseBuffer();
SelectObject(hdc, hOldFont);
}
void draw3dtextWithCloseLight(LPCTSTR str, HFONT hFont, float cDepth, float dXoffset, float dYoffset, float dZoffset, float dXscale, float dYscale, float dZscale,
float dXrotate, float dYrotate, float dZrotate)
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
draw3dtextIgnoreLight(TEXT(str), hFont, cDepth, dXoffset, dYoffset, dZoffset, dXscale, dYscale, dZscale, dXrotate, dYrotate, dZrotate);
glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
}
void draw3dtextIgnoreLight(LPCTSTR strText, HFONT hFont, float cDepth, float dXoffset, float dYoffset, float dZoffset, float dXscale, float dYscale, float dZscale,
float dXrotate, float dYrotate, float dZrotate)
{
HDC hdc = wglGetCurrentDC();
HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
UCHAR * pChar = (UCHAR*)strText/*.GetBuffer(strText.GetLength())*/;
int nListNum;
DWORD dwChar;
GLYPHMETRICSFLOAT pgmf[1];
glPushMatrix();
float m_dXOffset = dXoffset;
float m_dYOffset = dYoffset;
float m_dZOffset = dZoffset;
float m_dXScale = dXscale;
float m_dYScale = dYscale;
float m_dZScale = dZscale;
float m_dXRotate = dXrotate;
float m_dYRotate = dYrotate;
float m_dZRotate = dZrotate;
glTranslatef(m_dXOffset, m_dYOffset, m_dZOffset);
//Scale
glScaled(m_dXScale, m_dYScale, m_dZScale);
//Rotate around X-axis
glRotated(m_dXRotate, 1.0, 0.0, 0.0);
//Rotate around Y-axis
glRotated(m_dYRotate, 0.0, 1.0, 0.0);
//Rotate around Z-axis
glRotated(m_dZRotate, 0.0, 0.0, 1.0);
glColor4f(0.0, 1.0, 0.0,0.5); //绿色 半透明
for (int i = 0; i < _tcslen(strText)/*strText.GetLength()*/; i++)
{
if (IsDBCSLeadByte((BYTE)pChar[i]))
{
dwChar = (DWORD)((pChar[i] << 8) | pChar[i + 1]);
i++;
}
else dwChar = pChar[i];
nListNum = glGenLists(1);
/*可以用于创建三维的字体
hdc 字体的设备上下文
first 要转换为显示列表的第一个字符
count 要转化为显示列表字符的个数
listBase 显示列表的基数
deviation 指定与实际轮廓的最大偏移量
extrusion 指定字体在z轴负方向的值。通过修改这个值就可以显示3D字符,字体的深度
format 指定显示列表线段或多边形
lpgmf 接受字符的地址,用于保存创建字体的一些信息,通常其指向的空间长度是不小于创建的显示列表数的
*/
wglUseFontOutlines(hdc,
dwChar,
1,
nListNum,
0.0f,
cDepth,
WGL_FONT_POLYGONS, //WGL_FONT_POLYGONS
pgmf
);
glCallList(nListNum);
glDeleteLists(nListNum, 1);
}
//restore the original angle around Z-axis
glRotated(-1.0f * m_dZRotate, 0.0, 0.0, 1.0);
//restore the original angle around Y-axis
glRotated(-1.0f * m_dYRotate, 0.0, 1.0, 0.0);
//restore the original angle around X-axis
glRotated(-1.0f * m_dXRotate, 1.0, 0.0, 0.0);
//restore the original scale
glScaled(1.0 / m_dXScale, 1.0 / m_dYScale, 1.0 / m_dZScale);
glTranslated(-m_dXOffset, -m_dYOffset, -m_dZOffset);
glPopMatrix();
//strText.ReleaseBuffer();
SelectObject(hdc, hOldFont);
}
//检测换行符,如果有换行符,则把字符分行
void draw3dMultiLineText(){
}
5 vs工程结构图
- AR多标签识别程序2
- AR多标签识别程序1
- AR多标签识别
- AR多标签识别3
- unity AR实物识别
- 多标识AR程序分析(一)
- 多标识AR程序分析(一)
- AR发票导入程序
- 高通AR增强现实多卡识别和扩展跟踪Unity
- 高通AR增强现实多卡识别和扩展跟踪Unity
- 利用Vuforia开发一个AR卡牌对战(一):多图识别+EventHandler框架
- AR/VR learning (2)--unity3D在android 上的手势识别与检测
- HoloLens开发2:Vuforia结合HoloLens开发AR(识别图像)
- Qualcomm AR之目标识别、跟踪
- AR demo 简单的平面图像识别
- 手势识别在AR中的未来
- AR入门系列-06-Vuforia文字识别
- AR入门系列-06-Vuforia文字识别
- ios中播放gif动画
- CodeForces 484 D.Kindergarten(dp)
- Netty4.0的DefaultHttpRequest与FullHttpRequest
- MongoDB基础使用教程
- Java抽象类
- AR多标签识别程序2
- 【matlab】利用sortrows进行Z字形扫描
- 基于RollPagerView实现图片轮播功能
- C/C++ Windows移植到Linux
- Android Telephony分析(一) ---- Phone详解
- 敏捷开发之Scrum扫盲篇
- Android中使EditText失去焦点,edittext禁止弹出键盘
- 网易实习——消除重复元素
- Struts2的介绍和入门(一)