void Widget::initMPU6050()
{
wiringPiSetup () ;
fd = wiringPiI2CSetup (SlaveAddress);
if (fd >= 0) { // fd 为负数,说明IIC连接失败
//printf("fd = %d\n",fd);
qDebug() << "fd =" << fd;
wiringPiI2CWriteReg8(fd,PWR_MGMT_1,0x00); // 开启温度检测 关闭休眠
wiringPiI2CWriteReg8(fd,SMPLRT_DIV, 0x07);
wiringPiI2CWriteReg8(fd,CONFIG, 0x06);
wiringPiI2CWriteReg8(fd,GYRO_CONFIG, 0x18);
wiringPiI2CWriteReg8(fd,ACCEL_CONFIG, 0x01);
}
else {
printf("IIC初始化失败");
}
}
double Widget::getDataangle(quint8 reg_address)
{
// quint8 H = wiringPiI2CReadReg8(fd,reg_address);
// quint8 L = wiringPiI2CReadReg8(fd,reg_address + 1);
// return (short)((H << 8) | L) /32768.0*180;
return ((wiringPiI2CReadReg8(fd,reg_address) << 8) | wiringPiI2CReadReg8(fd,reg_address + 1))/32768.0*180;
}
double Widget::getDataaccel(quint8 reg_address)
{
return ((wiringPiI2CReadReg8(fd,reg_address) << 8) | wiringPiI2CReadReg8(fd,reg_address + 1))/32768.0*16;
}
double Widget::getDAtatemp(quint8 reg_address)
{
int H = wiringPiI2CReadReg8(fd,reg_address);
int L = wiringPiI2CReadReg8(fd,reg_address + 1);
return (short)((H << 8) | L) / 340 + 36.53;
//return ((wiringPiI2CReadReg8(fd,reg_address) << 8) | wiringPiI2CReadReg8(fd,reg_address + 1))/340.0+36.53;
}
//定义显示图标
point1 = Point(950,50);
point2 = Point(950,200);
point3 = Point(950,350);
point4 = Point(0,50);
point5 = Point(0,200);
point6 = Point(0,350);
point7 = Point(0,700);
//获取传感器数据
X6050angle = QString("%1").arg(QString::number(getDataangle(ACCEL_XOUT_H),'f',3));
Y6050angle = QString("%1").arg(QString::number(getDataangle(ACCEL_YOUT_H),'f',3));
Z6050angle = QString("%1").arg(QString::number(getDataangle(ACCEL_ZOUT_H),'f',3));
X6050accel = QString("%1").arg(QString::number(getDataaccel(GYRO_XOUT_H),'f',3));
Y6050accel = QString("%1").arg(QString::number(getDataaccel(GYRO_YOUT_H),'f',3));
Z6050accel = QString("%1").arg(QString::number(getDataaccel(GYRO_ZOUT_H),'f',3));
TEMP6050 = QString("%1").arg(QString::number(getDAtatemp(TEMP_OUT_H),'f',2));
//显示
putText(srcImageL,X6050angle.toStdString(),point1,Font_face,2,Scalar::all(255),2);
putText(srcImageL,Y6050angle.toStdString(),point2,Font_face,2,Scalar::all(255),2);
putText(srcImageL,Z6050angle.toStdString(),point3,Font_face,2,Scalar::all(255),2);
putText(srcImageL,X6050accel.toStdString(),point4,Font_face,2,Scalar::all(255),2);
putText(srcImageL,Y6050accel.toStdString(),point5,Font_face,2,Scalar::all(255),2);
putText(srcImageL,Z6050accel.toStdString(),point6,Font_face,2,Scalar::all(255),2);
putText(srcImageL,TEMP6050.toStdString(),point7,Font_face,2,Scalar::all(255),2);
人脸检测
faceCascade.load("/home/pi/Desktop/Resources/haarcascade_frontalface_default.xml");
if(faceCascade.empty()){cout << "XML is not loaded" << endl;}
vector<Rect> faces;
faceCascade.detectMultiScale(srcImageL,faces,1.1,10);
for (int i = 0; i < faces.size(); i++)
{
Mat imgCrop = srcImageL(faces[i]);
rectangle(srcImageL,faces[i].tl(),faces[i].br(),Scalar(255,0,255),2);
}
#define SMPLRT_DIV 0x19 //陀螺仪采样率,典型值:0x07(125Hz)
#define CONFIG 0x1A //低通滤波频率,典型值:0x06(5Hz)
#define GYRO_CONFIG 0x1B //陀螺仪自检及测量范围,典型值:0x18(不自检,2000deg/s)
#define ACCEL_CONFIG 0x1C //加速计自检、测量范围及高通滤波频率,典型值:0x01(不自检,2G,5Hz)
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48
#define PWR_MGMT_1 0x6B //电源管理,典型值:0x00(正常启用)
#define WHO_AM_I 0x75 //IIC地址寄存器(默认数值0x68,只读)
#define SlaveAddress 0x68 //MPU6050器件地址