只需一步,快速开始
签到天数: 699 天
[LV.9]以坛为家II
OpenCV Bot实际上通过图像处理检测或跟踪任何实时对象。此应用程序可以使用其颜色检测任何对象,并在手机屏幕中创建X,Y位置和区域area,使用此应用程序,数据通过蓝牙发送到微控制器。它已经过蓝牙模块测试,适用于各种设备。我们通过手机下载此APP来实现颜色的追踪,通过蓝牙发送数据到Arduino UNO上进行数据分析后执行运动命令。
在手机上安装APP软件(见底部,软件已被下架)安装后图如下:
连接蓝牙(先在设置里匹配好,pin1234,再到APP里面选择连接)
登录/注册后可看大图 OpenCV Bot1.png (38.71 KB, 下载次数: 37) 下载附件 2019-12-2 16:54 上传 点击需要识别的物体(颜色不要与周围有冲突,影响识别效果) 登录/注册后可看大图 OpenCVBot2.jpg (181.27 KB, 下载次数: 59) 下载附件 2019-12-3 14:29 上传 识别中我们可以看到在图像的上部显示出X,Y,Area值,X表示左右,Y表示上下,Area表示前后,通过得到的数值我们可以很轻松的判断球向哪里运动,通过蓝牙传输数据到Arduino UNO主板中,我们就可以控制机器人怎么运动。(由于抓捕物体的大小不同,参数值也会不同,所以需要根据实际使用的物体大小进行选取判断值)底盘车架选用灵活的全向轮,行走灵活,无死角的旋转和行走,方便实行我们跟随目标;当然,Mecanum wheels也是不错的选择。我们安装好底盘,每个轮子使用单独的驱动(灵活运动的关键),具体配件如下:1:4WD全向轮底盘,3WD全向轮底盘,麦克纳姆轮底盘都可以;2:安卓手机,支持安卓5以上;3:Arduino UNO R3主板,兼容型号都可以,或者其余单片机等等;4:2块PM-R3,叠加结构,引脚相同所以需要外部加工修改引脚的位置;5:18650电池,3S;6:固定手机的支架;7:最好准备防滑毯,效果会很好; 如下是安装好的样子: 登录/注册后可看大图 omniwheels.jpg (118.42 KB, 下载次数: 44) 下载附件 2019-12-3 13:15 上传 示例代码如下,检测的X,Y,Area值在串口里面查看,代码驱动部分需要自行修改以适配不同的电机驱动[C] 纯文本查看 复制代码[b][size=3]#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); // RX, TX //Initialize global variables String bluetoothRead; unsigned short x, y, area; unsigned short strLength; //Configure motor pin int pwmMotorA = 11; int pwmMotorB = 10; int leftMotorA = 9; int leftMotorB = 8; int rightMotorA = 7; int rightMotorB = 6; //Set motor speed int motorSpeed = 140; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); Serial.println("OpenCV Bot"); // Set the baud rate of (HC-05) Bluetooth module mySerial.begin(38400); //Setup pins pinMode(pwmMotorA, OUTPUT); pinMode(pwmMotorB, OUTPUT); pinMode(leftMotorA, OUTPUT); pinMode(leftMotorB, OUTPUT); pinMode(rightMotorA, OUTPUT); pinMode(rightMotorB, OUTPUT); analogWrite(pwmMotorA, motorSpeed); analogWrite(pwmMotorB, motorSpeed); } void loop() { register byte ndx = 0; char commandbuffer[50]; if (mySerial.available() > 0) { delay(10); while ( mySerial.available() && ndx < 50) { commandbuffer[ndx++] = mySerial.read(); } commandbuffer[ndx] = '\0'; bluetoothRead = (char*)commandbuffer; strLength = bluetoothRead.length(); //Serial.println(bluetoothRead); if (bluetoothRead.substring(0, 1).equals("X")) { uint8_t pos, i = 1; while (bluetoothRead.substring(i, i + 1) != ("Y")) { i++; } x = bluetoothRead.substring(1, i).toInt(); //Serial.print("X: "); //Serial.println(x); pos = i + 1; while (bluetoothRead.substring(i, i + 1) != ("A")) { i++; } y = bluetoothRead.substring(pos, i).toInt(); //Serial.print("Y: "); //Serial.println(y); area = bluetoothRead.substring(i + 1, strLength).toInt(); //Serial.print("Area: "); //Serial.println(area); if (x < 750) { Serial.println("Left"); Left(); } if (x > 1100) { Serial.println("Right"); Right(); } if (x >= 750 && x <= 1100) { if (area < 150) { Serial.println("Forward"); Forward(); } if (area >= 150 && area <= 250) { Serial.println("Stop"); Stop(); } if (area > 250) { Serial.println("Back"); Back(); } } } } // all data has been sent, and the buffer is empty. Serial.flush(); } void Left() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Right() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Forward() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Back() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Stop() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, LOW); }[b][size=3] 串口打印值如下: 登录/注册后可看大图 串口输出.png (64.03 KB, 下载次数: 47) 下载附件 2019-12-3 14:30 上传
OpenCV Bot1.png (38.71 KB, 下载次数: 37)
下载附件
2019-12-2 16:54 上传
点击需要识别的物体(颜色不要与周围有冲突,影响识别效果)
登录/注册后可看大图 OpenCVBot2.jpg (181.27 KB, 下载次数: 59) 下载附件 2019-12-3 14:29 上传 识别中我们可以看到在图像的上部显示出X,Y,Area值,X表示左右,Y表示上下,Area表示前后,通过得到的数值我们可以很轻松的判断球向哪里运动,通过蓝牙传输数据到Arduino UNO主板中,我们就可以控制机器人怎么运动。(由于抓捕物体的大小不同,参数值也会不同,所以需要根据实际使用的物体大小进行选取判断值)底盘车架选用灵活的全向轮,行走灵活,无死角的旋转和行走,方便实行我们跟随目标;当然,Mecanum wheels也是不错的选择。我们安装好底盘,每个轮子使用单独的驱动(灵活运动的关键),具体配件如下:1:4WD全向轮底盘,3WD全向轮底盘,麦克纳姆轮底盘都可以;2:安卓手机,支持安卓5以上;3:Arduino UNO R3主板,兼容型号都可以,或者其余单片机等等;4:2块PM-R3,叠加结构,引脚相同所以需要外部加工修改引脚的位置;5:18650电池,3S;6:固定手机的支架;7:最好准备防滑毯,效果会很好; 如下是安装好的样子: 登录/注册后可看大图 omniwheels.jpg (118.42 KB, 下载次数: 44) 下载附件 2019-12-3 13:15 上传 示例代码如下,检测的X,Y,Area值在串口里面查看,代码驱动部分需要自行修改以适配不同的电机驱动[C] 纯文本查看 复制代码[b][size=3]#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); // RX, TX //Initialize global variables String bluetoothRead; unsigned short x, y, area; unsigned short strLength; //Configure motor pin int pwmMotorA = 11; int pwmMotorB = 10; int leftMotorA = 9; int leftMotorB = 8; int rightMotorA = 7; int rightMotorB = 6; //Set motor speed int motorSpeed = 140; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); Serial.println("OpenCV Bot"); // Set the baud rate of (HC-05) Bluetooth module mySerial.begin(38400); //Setup pins pinMode(pwmMotorA, OUTPUT); pinMode(pwmMotorB, OUTPUT); pinMode(leftMotorA, OUTPUT); pinMode(leftMotorB, OUTPUT); pinMode(rightMotorA, OUTPUT); pinMode(rightMotorB, OUTPUT); analogWrite(pwmMotorA, motorSpeed); analogWrite(pwmMotorB, motorSpeed); } void loop() { register byte ndx = 0; char commandbuffer[50]; if (mySerial.available() > 0) { delay(10); while ( mySerial.available() && ndx < 50) { commandbuffer[ndx++] = mySerial.read(); } commandbuffer[ndx] = '\0'; bluetoothRead = (char*)commandbuffer; strLength = bluetoothRead.length(); //Serial.println(bluetoothRead); if (bluetoothRead.substring(0, 1).equals("X")) { uint8_t pos, i = 1; while (bluetoothRead.substring(i, i + 1) != ("Y")) { i++; } x = bluetoothRead.substring(1, i).toInt(); //Serial.print("X: "); //Serial.println(x); pos = i + 1; while (bluetoothRead.substring(i, i + 1) != ("A")) { i++; } y = bluetoothRead.substring(pos, i).toInt(); //Serial.print("Y: "); //Serial.println(y); area = bluetoothRead.substring(i + 1, strLength).toInt(); //Serial.print("Area: "); //Serial.println(area); if (x < 750) { Serial.println("Left"); Left(); } if (x > 1100) { Serial.println("Right"); Right(); } if (x >= 750 && x <= 1100) { if (area < 150) { Serial.println("Forward"); Forward(); } if (area >= 150 && area <= 250) { Serial.println("Stop"); Stop(); } if (area > 250) { Serial.println("Back"); Back(); } } } } // all data has been sent, and the buffer is empty. Serial.flush(); } void Left() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Right() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Forward() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Back() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Stop() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, LOW); }[b][size=3] 串口打印值如下: 登录/注册后可看大图 串口输出.png (64.03 KB, 下载次数: 47) 下载附件 2019-12-3 14:30 上传
OpenCVBot2.jpg (181.27 KB, 下载次数: 59)
2019-12-3 14:29 上传
识别中我们可以看到在图像的上部显示出X,Y,Area值,X表示左右,Y表示上下,Area表示前后,通过得到的数值我们可以很轻松的判断球向哪里运动,通过蓝牙传输数据到Arduino UNO主板中,我们就可以控制机器人怎么运动。(由于抓捕物体的大小不同,参数值也会不同,所以需要根据实际使用的物体大小进行选取判断值)
底盘车架选用灵活的全向轮,行走灵活,无死角的旋转和行走,方便实行我们跟随目标;当然,Mecanum wheels也是不错的选择。我们安装好底盘,每个轮子使用单独的驱动(灵活运动的关键),具体配件如下:
1:4WD全向轮底盘,3WD全向轮底盘,麦克纳姆轮底盘都可以;
2:安卓手机,支持安卓5以上;
3:Arduino UNO R3主板,兼容型号都可以,或者其余单片机等等;
4:2块PM-R3,叠加结构,引脚相同所以需要外部加工修改引脚的位置;
5:18650电池,3S;
6:固定手机的支架;
7:最好准备防滑毯,效果会很好;
如下是安装好的样子:
登录/注册后可看大图 omniwheels.jpg (118.42 KB, 下载次数: 44) 下载附件 2019-12-3 13:15 上传 示例代码如下,检测的X,Y,Area值在串口里面查看,代码驱动部分需要自行修改以适配不同的电机驱动[C] 纯文本查看 复制代码[b][size=3]#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); // RX, TX //Initialize global variables String bluetoothRead; unsigned short x, y, area; unsigned short strLength; //Configure motor pin int pwmMotorA = 11; int pwmMotorB = 10; int leftMotorA = 9; int leftMotorB = 8; int rightMotorA = 7; int rightMotorB = 6; //Set motor speed int motorSpeed = 140; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); Serial.println("OpenCV Bot"); // Set the baud rate of (HC-05) Bluetooth module mySerial.begin(38400); //Setup pins pinMode(pwmMotorA, OUTPUT); pinMode(pwmMotorB, OUTPUT); pinMode(leftMotorA, OUTPUT); pinMode(leftMotorB, OUTPUT); pinMode(rightMotorA, OUTPUT); pinMode(rightMotorB, OUTPUT); analogWrite(pwmMotorA, motorSpeed); analogWrite(pwmMotorB, motorSpeed); } void loop() { register byte ndx = 0; char commandbuffer[50]; if (mySerial.available() > 0) { delay(10); while ( mySerial.available() && ndx < 50) { commandbuffer[ndx++] = mySerial.read(); } commandbuffer[ndx] = '\0'; bluetoothRead = (char*)commandbuffer; strLength = bluetoothRead.length(); //Serial.println(bluetoothRead); if (bluetoothRead.substring(0, 1).equals("X")) { uint8_t pos, i = 1; while (bluetoothRead.substring(i, i + 1) != ("Y")) { i++; } x = bluetoothRead.substring(1, i).toInt(); //Serial.print("X: "); //Serial.println(x); pos = i + 1; while (bluetoothRead.substring(i, i + 1) != ("A")) { i++; } y = bluetoothRead.substring(pos, i).toInt(); //Serial.print("Y: "); //Serial.println(y); area = bluetoothRead.substring(i + 1, strLength).toInt(); //Serial.print("Area: "); //Serial.println(area); if (x < 750) { Serial.println("Left"); Left(); } if (x > 1100) { Serial.println("Right"); Right(); } if (x >= 750 && x <= 1100) { if (area < 150) { Serial.println("Forward"); Forward(); } if (area >= 150 && area <= 250) { Serial.println("Stop"); Stop(); } if (area > 250) { Serial.println("Back"); Back(); } } } } // all data has been sent, and the buffer is empty. Serial.flush(); } void Left() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Right() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Forward() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Back() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Stop() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, LOW); }[b][size=3] 串口打印值如下: 登录/注册后可看大图 串口输出.png (64.03 KB, 下载次数: 47) 下载附件 2019-12-3 14:30 上传
omniwheels.jpg (118.42 KB, 下载次数: 44)
2019-12-3 13:15 上传
示例代码如下,检测的X,Y,Area值在串口里面查看,代码驱动部分需要自行修改以适配不同的电机驱动
[C] 纯文本查看 复制代码[b][size=3]#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); // RX, TX //Initialize global variables String bluetoothRead; unsigned short x, y, area; unsigned short strLength; //Configure motor pin int pwmMotorA = 11; int pwmMotorB = 10; int leftMotorA = 9; int leftMotorB = 8; int rightMotorA = 7; int rightMotorB = 6; //Set motor speed int motorSpeed = 140; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); Serial.println("OpenCV Bot"); // Set the baud rate of (HC-05) Bluetooth module mySerial.begin(38400); //Setup pins pinMode(pwmMotorA, OUTPUT); pinMode(pwmMotorB, OUTPUT); pinMode(leftMotorA, OUTPUT); pinMode(leftMotorB, OUTPUT); pinMode(rightMotorA, OUTPUT); pinMode(rightMotorB, OUTPUT); analogWrite(pwmMotorA, motorSpeed); analogWrite(pwmMotorB, motorSpeed); } void loop() { register byte ndx = 0; char commandbuffer[50]; if (mySerial.available() > 0) { delay(10); while ( mySerial.available() && ndx < 50) { commandbuffer[ndx++] = mySerial.read(); } commandbuffer[ndx] = '\0'; bluetoothRead = (char*)commandbuffer; strLength = bluetoothRead.length(); //Serial.println(bluetoothRead); if (bluetoothRead.substring(0, 1).equals("X")) { uint8_t pos, i = 1; while (bluetoothRead.substring(i, i + 1) != ("Y")) { i++; } x = bluetoothRead.substring(1, i).toInt(); //Serial.print("X: "); //Serial.println(x); pos = i + 1; while (bluetoothRead.substring(i, i + 1) != ("A")) { i++; } y = bluetoothRead.substring(pos, i).toInt(); //Serial.print("Y: "); //Serial.println(y); area = bluetoothRead.substring(i + 1, strLength).toInt(); //Serial.print("Area: "); //Serial.println(area); if (x < 750) { Serial.println("Left"); Left(); } if (x > 1100) { Serial.println("Right"); Right(); } if (x >= 750 && x <= 1100) { if (area < 150) { Serial.println("Forward"); Forward(); } if (area >= 150 && area <= 250) { Serial.println("Stop"); Stop(); } if (area > 250) { Serial.println("Back"); Back(); } } } } // all data has been sent, and the buffer is empty. Serial.flush(); } void Left() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Right() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Forward() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Back() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Stop() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, LOW); }[b][size=3]
[b][size=3]#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); // RX, TX //Initialize global variables String bluetoothRead; unsigned short x, y, area; unsigned short strLength; //Configure motor pin int pwmMotorA = 11; int pwmMotorB = 10; int leftMotorA = 9; int leftMotorB = 8; int rightMotorA = 7; int rightMotorB = 6; //Set motor speed int motorSpeed = 140; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); Serial.println("OpenCV Bot"); // Set the baud rate of (HC-05) Bluetooth module mySerial.begin(38400); //Setup pins pinMode(pwmMotorA, OUTPUT); pinMode(pwmMotorB, OUTPUT); pinMode(leftMotorA, OUTPUT); pinMode(leftMotorB, OUTPUT); pinMode(rightMotorA, OUTPUT); pinMode(rightMotorB, OUTPUT); analogWrite(pwmMotorA, motorSpeed); analogWrite(pwmMotorB, motorSpeed); } void loop() { register byte ndx = 0; char commandbuffer[50]; if (mySerial.available() > 0) { delay(10); while ( mySerial.available() && ndx < 50) { commandbuffer[ndx++] = mySerial.read(); } commandbuffer[ndx] = '\0'; bluetoothRead = (char*)commandbuffer; strLength = bluetoothRead.length(); //Serial.println(bluetoothRead); if (bluetoothRead.substring(0, 1).equals("X")) { uint8_t pos, i = 1; while (bluetoothRead.substring(i, i + 1) != ("Y")) { i++; } x = bluetoothRead.substring(1, i).toInt(); //Serial.print("X: "); //Serial.println(x); pos = i + 1; while (bluetoothRead.substring(i, i + 1) != ("A")) { i++; } y = bluetoothRead.substring(pos, i).toInt(); //Serial.print("Y: "); //Serial.println(y); area = bluetoothRead.substring(i + 1, strLength).toInt(); //Serial.print("Area: "); //Serial.println(area); if (x < 750) { Serial.println("Left"); Left(); } if (x > 1100) { Serial.println("Right"); Right(); } if (x >= 750 && x <= 1100) { if (area < 150) { Serial.println("Forward"); Forward(); } if (area >= 150 && area <= 250) { Serial.println("Stop"); Stop(); } if (area > 250) { Serial.println("Back"); Back(); } } } } // all data has been sent, and the buffer is empty. Serial.flush(); } void Left() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Right() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Forward() { digitalWrite(leftMotorA, HIGH); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, HIGH); digitalWrite(rightMotorB, LOW); } void Back() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, HIGH); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, HIGH); } void Stop() { digitalWrite(leftMotorA, LOW); digitalWrite(leftMotorB, LOW); digitalWrite(rightMotorA, LOW); digitalWrite(rightMotorB, LOW); }[b][size=3]
串口打印值如下:
登录/注册后可看大图 串口输出.png (64.03 KB, 下载次数: 47) 下载附件 2019-12-3 14:30 上传
串口输出.png (64.03 KB, 下载次数: 47)
2019-12-3 14:30 上传
Opencvbot_Omniwheels_demo.rar
2019-12-3 11:32 上传
点击文件名下载附件
1.34 KB, 阅读权限: 10, 下载次数: 39
APK.zip
2021-7-1 08:16 上传
1.48 MB, 下载次数: 4
使用道具 举报
签到天数: 10 天
[LV.3]偶尔看看II
该用户从未签到
anshilike 发表于 2020-5-11 01:57 opencv manager package was not found 科学上网也破不了 怎么办 谷歌市场也搜不到这manager package
签到天数: 6 天
[LV.2]偶尔看看I
laoguang 发表于 2021-6-27 21:12 APK下载有点问题 大小都是0KB
本版积分规则 发表回复 回帖后跳转到最后一页
|小黑屋|联系我们|YFROBOT ( 苏ICP备20009901号-2 )
GMT+8, 2024-11-21 17:41 , Processed in 0.077236 second(s), 28 queries .
Powered by Discuz! X3.1
© 2001-2013 Comsenz Inc.