Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	LICENSE
  • Loading branch information
scflow committed Dec 16, 2024
2 parents 79db7f1 + 5159905 commit a842319
Show file tree
Hide file tree
Showing 41 changed files with 1,841 additions and 706 deletions.
34 changes: 34 additions & 0 deletions Audio/play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pygame
import threading

file = 'Audio/doorbell.mp3'

def play_audio_blocking(audio_file=file):
"""
在新线程中播放音频文件,并在播放完毕后返回。
:param audio_file: 音频文件的路径
"""
# 初始化pygame
pygame.mixer.init()

# 加载音频文件
pygame.mixer.music.load(audio_file)

# 播放音频
pygame.mixer.music.play()

# 等待音频播放完毕
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)

# 退出pygame mixer
pygame.mixer.quit()

def play_audio_non_blocking(audio_file=file):
"""
在新线程中播放音频文件,不会阻塞主程序。
:param audio_file: 音频文件的路径
"""
# 创建并启动线程来播放音频
audio_thread = threading.Thread(target=play_audio_blocking, args=(audio_file,))
audio_thread.start()
Binary file added Audio/stop.mp3
Binary file not shown.
14 changes: 14 additions & 0 deletions Audio/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pygame

# 初始化pygame
pygame.init()

# 加载音频文件
pygame.mixer.music.load('doorbell.mp3')

# 播放音频
pygame.mixer.music.play()

# 保持程序运行,直到音频播放完毕
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
204 changes: 204 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -199,3 +200,206 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=======
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
>>>>>>> dev
78 changes: 74 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,77 @@
## CV Car
# CV Car

具体使用说明请看README文件夹
## 简介

Github项目地址 https://github.com/scflow/CV_Car
树莓派循迹小车,实现功能包括循迹,停车,避障。完成度六七成的样子。

Gitee项目地址 https://gitee.com/gongjc-xy/CV_Car
## 仓库地址

| 仓库 | 地址 |
| ------ | ---------------------------------- |
| Github | https://github.com/scflow/CV_Car |
| Gitee | https://gitee.com/gongjc-xy/CV_Car |

## 运行设备

树莓派4B(Raspiberry4B)

## 所需环境

python3(所需pip包见requirements.txt)

### 选配

如果需要使用[Network RC远程遥控](https://network-rc.esonwong.com/),系统建议使用raspios-buster-armhf,三者建议均对上,否则大概率访问不了,下载镜像 [2021-12-02-raspios-buster-armhf.zip](https://downloads.raspberrypi.org/raspios_oldstable_armhf/images/raspios_oldstable_armhf-2021-12-02/2021-12-02-raspios-buster-armhf.zip),详情见[树莓派上安装-network-rc](https://network-rc.esonwong.com/guide.html#%E6%A0%91%E8%8E%93%E6%B4%BE%E4%B8%8A%E5%AE%89%E8%A3%85-network-rc)

当然,如果不需要,推荐64位Ubuntu

## 代码思路

- **循线**: 与传统循线类似,通过膨胀复制滤波等操作获得大致线条,然后使用霍夫变换拟合直线,并计算数据转化为边线对象,效果还不错,就是只能转化为直线,太弯弯绕绕或者直角拐弯肯定不行,边线上顶点取平均值记中点,通过PID与卡尔曼滤波综合控制舵机
- **校正**: 摄像头存在一定畸变,干扰拟合,因此使用了校正,具体方法CSDN上有,但如果需求不是那么强烈也可以不矫正,实测运行时python校正一次20ms左右
- **目标检测**: 起初是用的特征匹配,如果性能足够的话还是可以的,但是树莓派性能还是差了点,实时性不够,所以几乎不可用,后来换了模型,采用的https://github.com/dog-qiuqiu/FastestDet这个的目标检测模型,比较轻量化,也适合简单物体检测
- **颜色单一物体检测**: 参考了车流量检测的代码,将单色物体HSV过滤后,腐蚀后膨胀,融合成一个整体,避免反光等原因识别出多个小的
- **日志**:使用了loguru库,同时代码中通过单帧图片保存保留关键帧图片,便于后续分析

## 项目运行

### 安装准备

```bash
git clone https://gitee.com/gongjc-xy/CV_Car.git
cd CV_Car
chmod +x ./install.sh
./install.sh
```

如果一切顺利,接下来就可以尝试运行,run2是执行代码的指令,run2 后增加对应该文件夹下python文件也可执行对应python代码

```bash
run2
```

## 实测表现

- 运行时大概有17帧左右,如果有识别任务可能只有10或者更低
- 循线效果还行,断断续续的线也能走,但是如果遇到光斑效果依旧较差
- 检测效果一般,稳定性不强

## 小Tips

Network RC远程遥控驾驶远程往往是需要代理服务器的,但是如果服务器网络一般,远程遥控就会很卡,体验感是非常差的

代理其实是相当于把这个端口号与服务器的对应端口号绑定(当然我讲的可能不对),本来我们也是可以用WiFi连接下的地址192.168.xxx.xxx:8088之类的进行连接,但假如访问网页的设备没连接这个WiFi,那就连不上,因为这是局域网,而如果想要随处可连,其实完全可以绕过代理,走公网。

最主要的其实是这个端口号,通过设备IP地址加该端口号便可以访问,ipv4与ipv6都是可以的,ipv4一般情况下是只有局域网的,公网数量有限,在小车上几乎不可能有的,ipv6呢,由于其数量庞大,同时可以分配局域网和公网,当然,公网ipv6不是永久的,每隔一段时间便会换一个。

终端中输入ifconfig(windows是ipconfig)即可查看,如下图(图片取自[Windows 10 Insider build 14965 中的 ifconfig 和网络连接枚举支持](https://devblogs.microsoft.com/commandline/ifconfig-and-network-connection-enumeration-support-in-windows-10-insider-build-14965/)),inet就是ipv4的地址,而inet6自然就是ipv6了,fe80开头那段就是局域网的,剩下的就是公网ip了,ipv6加端口号访问网站百度搜一搜就行,[inet6地址]:端口号![ifconfig截图](https://devblogs.microsoft.com/wp-content/uploads/sites/33/2019/02/ifconfig-600x416.png)

如果是走流量、基站,一般都会给公网ipv6,如果是WiFi,就要看支不支持了,这不好说,有的可能并不会开通ipv6。所以远程遥控还是要推荐走4G/5G

单次公网ipv6租期有限,而且作为玩具小车,安全隐患还是不大的,还担心可以结合运维面板配下防火墙




如果代码运行有问题,可能是版本问题,也可能是我提交的代码有问题,漏交了或者错交了,代码问题可以提issue反馈,或者发邮件给我
后期大概率也不会改动代码了,代码看起来挺多,但是很烂,功能后面越写越分不清,代码命名混乱,但我觉得有几个思路还是可以的,如果有什么问题想问的,可以发邮件给我,hyperslip@outlook.com
37 changes: 0 additions & 37 deletions README/README.md

This file was deleted.

Loading

0 comments on commit a842319

Please sign in to comment.