├── LICENSE ├── README.md ├── TestUI01.py ├── User.py ├── computecolor.py ├── fire_detection.py ├── infrad_avoid.py ├── passive_buzzer.py ├── server.py ├── testmjpg - 2.py ├── testmjpg.py └── tracking_2.py /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raspberry-Pi-smart-car 2 | 硬件课程设计,树莓派智能小车。 3 | 4 | 因为软件代码要和硬件相配合,所以这些代码肯定不能直接使用。但是相信其中的写法会对你有帮助。 5 | 6 | computecolor.py计算图片中指定点的HSV值。用于颜色识别阈值的确定。 7 | fire_detection.py火焰检测。 8 | infrad_aviod.py自动避障,用到了红外和超声波。 9 | passive_buzzer.py测试蜂鸣器 10 | server.py服务端,在树莓派上运行,用于与自己的电脑进行socket通信。 11 | testmjpg-2.py两种颜色识别追踪 12 | testmjpg.py一种颜色识别追踪 13 | tracking_2.py自动循迹 14 | 15 | 以上除了颜色识别是在自己电脑上运行之外,其它都是在树莓派上运行。 16 | 17 | # 视频演示地址 18 | [树莓派智能小车功能展示与代码分享](https://www.bilibili.com/video/BV1tv411H7jh) 19 | 20 | # 交流 21 | 有问题可以提issue 22 | 不过提问之前最好先看看这篇文章[提问的智慧](https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md) 23 | -------------------------------------------------------------------------------- /TestUI01.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'TestUI01.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.9.2 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt5 import QtCore, QtGui, QtWidgets 10 | 11 | class Ui_MainWindow(object): 12 | def setupUi(self, MainWindow): 13 | MainWindow.setObjectName("MainWindow") 14 | MainWindow.resize(1184, 853) 15 | self.centralwidget = QtWidgets.QWidget(MainWindow) 16 | self.centralwidget.setObjectName("centralwidget") 17 | self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget) 18 | self.verticalLayoutWidget.setGeometry(QtCore.QRect(240, 20, 967, 751)) 19 | self.verticalLayoutWidget.setObjectName("verticalLayoutWidget") 20 | self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget) 21 | self.verticalLayout.setContentsMargins(0, 0, 0, 0) 22 | self.verticalLayout.setObjectName("verticalLayout") 23 | self.labelView = QtWidgets.QLabel(self.verticalLayoutWidget) 24 | self.labelView.setObjectName("labelView") 25 | self.verticalLayout.addWidget(self.labelView) 26 | self.horizontalLayout = QtWidgets.QHBoxLayout() 27 | self.horizontalLayout.setObjectName("horizontalLayout") 28 | self.gridLayout_2 = QtWidgets.QGridLayout() 29 | self.gridLayout_2.setObjectName("gridLayout_2") 30 | self.pushButtonw = QtWidgets.QPushButton(self.verticalLayoutWidget) 31 | font = QtGui.QFont() 32 | font.setFamily("Agency FB") 33 | font.setPointSize(16) 34 | self.pushButtonw.setFont(font) 35 | self.pushButtonw.setObjectName("pushButtonw") 36 | self.gridLayout_2.addWidget(self.pushButtonw, 0, 1, 1, 1) 37 | self.pushButton_stop = QtWidgets.QPushButton(self.verticalLayoutWidget) 38 | font = QtGui.QFont() 39 | font.setFamily("Agency FB") 40 | font.setPointSize(16) 41 | self.pushButton_stop.setFont(font) 42 | self.pushButton_stop.setObjectName("pushButton_stop") 43 | self.gridLayout_2.addWidget(self.pushButton_stop, 1, 1, 1, 1) 44 | self.pushButtona = QtWidgets.QPushButton(self.verticalLayoutWidget) 45 | font = QtGui.QFont() 46 | font.setFamily("Agency FB") 47 | font.setPointSize(16) 48 | self.pushButtona.setFont(font) 49 | self.pushButtona.setObjectName("pushButtona") 50 | self.gridLayout_2.addWidget(self.pushButtona, 1, 0, 1, 1) 51 | self.pushButtons = QtWidgets.QPushButton(self.verticalLayoutWidget) 52 | font = QtGui.QFont() 53 | font.setFamily("Agency FB") 54 | font.setPointSize(16) 55 | self.pushButtons.setFont(font) 56 | self.pushButtons.setObjectName("pushButtons") 57 | self.gridLayout_2.addWidget(self.pushButtons, 2, 1, 1, 1) 58 | self.pushButtond = QtWidgets.QPushButton(self.verticalLayoutWidget) 59 | font = QtGui.QFont() 60 | font.setFamily("Agency FB") 61 | font.setPointSize(16) 62 | self.pushButtond.setFont(font) 63 | self.pushButtond.setObjectName("pushButtond") 64 | self.gridLayout_2.addWidget(self.pushButtond, 1, 2, 1, 1) 65 | self.horizontalLayout.addLayout(self.gridLayout_2) 66 | self.verticalLayout_3 = QtWidgets.QVBoxLayout() 67 | self.verticalLayout_3.setObjectName("verticalLayout_3") 68 | self.horizontalLayout_2 = QtWidgets.QHBoxLayout() 69 | self.horizontalLayout_2.setObjectName("horizontalLayout_2") 70 | self.label_3 = QtWidgets.QLabel(self.verticalLayoutWidget) 71 | font = QtGui.QFont() 72 | font.setFamily("楷体") 73 | font.setPointSize(20) 74 | self.label_3.setFont(font) 75 | self.label_3.setAlignment(QtCore.Qt.AlignCenter) 76 | self.label_3.setObjectName("label_3") 77 | self.horizontalLayout_2.addWidget(self.label_3) 78 | self.spinBox_speed = QtWidgets.QSpinBox(self.verticalLayoutWidget) 79 | font = QtGui.QFont() 80 | font.setFamily("Agency FB") 81 | font.setPointSize(20) 82 | self.spinBox_speed.setFont(font) 83 | self.spinBox_speed.setMinimum(10) 84 | self.spinBox_speed.setMaximum(50) 85 | self.spinBox_speed.setSingleStep(5) 86 | self.spinBox_speed.setProperty("value", 30) 87 | self.spinBox_speed.setObjectName("spinBox_speed") 88 | self.horizontalLayout_2.addWidget(self.spinBox_speed) 89 | self.verticalLayout_3.addLayout(self.horizontalLayout_2) 90 | self.pushButton_Connect = QtWidgets.QPushButton(self.verticalLayoutWidget) 91 | font = QtGui.QFont() 92 | font.setFamily("Agency FB") 93 | font.setPointSize(16) 94 | self.pushButton_Connect.setFont(font) 95 | self.pushButton_Connect.setObjectName("pushButton_Connect") 96 | self.verticalLayout_3.addWidget(self.pushButton_Connect) 97 | self.verticalLayout_3.setStretch(0, 1) 98 | self.verticalLayout_3.setStretch(1, 1) 99 | self.horizontalLayout.addLayout(self.verticalLayout_3) 100 | self.gridLayout = QtWidgets.QGridLayout() 101 | self.gridLayout.setObjectName("gridLayout") 102 | self.pushButtonDown = QtWidgets.QPushButton(self.verticalLayoutWidget) 103 | font = QtGui.QFont() 104 | font.setFamily("Agency FB") 105 | font.setPointSize(16) 106 | self.pushButtonDown.setFont(font) 107 | self.pushButtonDown.setObjectName("pushButtonDown") 108 | self.gridLayout.addWidget(self.pushButtonDown, 3, 1, 1, 1) 109 | self.pushButtonUp = QtWidgets.QPushButton(self.verticalLayoutWidget) 110 | font = QtGui.QFont() 111 | font.setFamily("Agency FB") 112 | font.setPointSize(16) 113 | self.pushButtonUp.setFont(font) 114 | self.pushButtonUp.setObjectName("pushButtonUp") 115 | self.gridLayout.addWidget(self.pushButtonUp, 1, 1, 1, 1) 116 | self.pushButtonLeft = QtWidgets.QPushButton(self.verticalLayoutWidget) 117 | font = QtGui.QFont() 118 | font.setFamily("Agency FB") 119 | font.setPointSize(16) 120 | self.pushButtonLeft.setFont(font) 121 | self.pushButtonLeft.setObjectName("pushButtonLeft") 122 | self.gridLayout.addWidget(self.pushButtonLeft, 2, 0, 1, 1) 123 | self.pushButtonRight = QtWidgets.QPushButton(self.verticalLayoutWidget) 124 | font = QtGui.QFont() 125 | font.setFamily("Agency FB") 126 | font.setPointSize(16) 127 | self.pushButtonRight.setFont(font) 128 | self.pushButtonRight.setObjectName("pushButtonRight") 129 | self.gridLayout.addWidget(self.pushButtonRight, 2, 2, 1, 1) 130 | self.pushButtonSS = QtWidgets.QPushButton(self.verticalLayoutWidget) 131 | font = QtGui.QFont() 132 | font.setFamily("Agency FB") 133 | font.setPointSize(16) 134 | self.pushButtonSS.setFont(font) 135 | self.pushButtonSS.setObjectName("pushButtonSS") 136 | self.gridLayout.addWidget(self.pushButtonSS, 2, 1, 1, 1) 137 | self.horizontalLayout.addLayout(self.gridLayout) 138 | self.verticalLayout.addLayout(self.horizontalLayout) 139 | self.verticalLayout.setStretch(0, 7) 140 | self.verticalLayout.setStretch(1, 3) 141 | self.label = QtWidgets.QLabel(self.centralwidget) 142 | self.label.setGeometry(QtCore.QRect(20, 30, 191, 211)) 143 | self.label.setObjectName("label") 144 | self.verticalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget) 145 | self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(20, 330, 181, 141)) 146 | self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2") 147 | self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2) 148 | self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) 149 | self.verticalLayout_2.setObjectName("verticalLayout_2") 150 | self.label_2 = QtWidgets.QLabel(self.verticalLayoutWidget_2) 151 | font = QtGui.QFont() 152 | font.setFamily("楷体") 153 | font.setPointSize(16) 154 | self.label_2.setFont(font) 155 | self.label_2.setAlignment(QtCore.Qt.AlignCenter) 156 | self.label_2.setObjectName("label_2") 157 | self.verticalLayout_2.addWidget(self.label_2) 158 | self.pushButton_follow = QtWidgets.QPushButton(self.verticalLayoutWidget_2) 159 | font = QtGui.QFont() 160 | font.setFamily("Agency FB") 161 | font.setPointSize(16) 162 | self.pushButton_follow.setFont(font) 163 | self.pushButton_follow.setObjectName("pushButton_follow") 164 | self.verticalLayout_2.addWidget(self.pushButton_follow) 165 | MainWindow.setCentralWidget(self.centralwidget) 166 | self.menubar = QtWidgets.QMenuBar(MainWindow) 167 | self.menubar.setGeometry(QtCore.QRect(0, 0, 1184, 30)) 168 | self.menubar.setObjectName("menubar") 169 | MainWindow.setMenuBar(self.menubar) 170 | self.statusbar = QtWidgets.QStatusBar(MainWindow) 171 | self.statusbar.setObjectName("statusbar") 172 | MainWindow.setStatusBar(self.statusbar) 173 | 174 | self.retranslateUi(MainWindow) 175 | QtCore.QMetaObject.connectSlotsByName(MainWindow) 176 | 177 | def retranslateUi(self, MainWindow): 178 | _translate = QtCore.QCoreApplication.translate 179 | MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) 180 | self.labelView.setText(_translate("MainWindow", "View")) 181 | self.pushButtonw.setText(_translate("MainWindow", "前进")) 182 | self.pushButton_stop.setText(_translate("MainWindow", "停止")) 183 | self.pushButtona.setText(_translate("MainWindow", "左转")) 184 | self.pushButtons.setText(_translate("MainWindow", "后退")) 185 | self.pushButtond.setText(_translate("MainWindow", "右转")) 186 | self.label_3.setText(_translate("MainWindow", "速度:")) 187 | self.pushButton_Connect.setText(_translate("MainWindow", "开始连接")) 188 | self.pushButtonDown.setText(_translate("MainWindow", "下")) 189 | self.pushButtonUp.setText(_translate("MainWindow", "上")) 190 | self.pushButtonLeft.setText(_translate("MainWindow", "左")) 191 | self.pushButtonRight.setText(_translate("MainWindow", "右")) 192 | self.pushButtonSS.setText(_translate("MainWindow", "释放云台")) 193 | self.label.setText(_translate("MainWindow", "LOGO")) 194 | self.label_2.setText(_translate("MainWindow", "功能列表")) 195 | self.pushButton_follow.setText(_translate("MainWindow", "物体跟随")) 196 | 197 | -------------------------------------------------------------------------------- /User.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PyQt5.QtCore import Qt, QTimer 3 | from PyQt5.QtGui import QIcon, QPixmap, QImage 4 | from PyQt5 import QtCore, QtGui, QtWidgets 5 | from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox 6 | from TestUI01 import Ui_MainWindow 7 | import cv2 8 | import sys 9 | import socket 10 | import time 11 | 12 | 13 | class fin(QtWidgets.QMainWindow, Ui_MainWindow): 14 | def __init__(self, parent=None): 15 | super(fin, self).__init__(parent=parent) 16 | self.setupUi(self) 17 | self.setStyleSheet("#MainWindow{border-image:url(bg.jpg)}") 18 | self.setWindowTitle('威天鸣Car') 19 | self.setWindowIcon(QIcon('icon.ico')) 20 | icon = QtGui.QPixmap('logo.png').scaled(self.label.width(), self.label.height(), Qt.KeepAspectRatio, 21 | Qt.SmoothTransformation) 22 | self.label.setPixmap(icon) 23 | 24 | self.pushButtonw.clicked.connect(self.on_Forward) 25 | self.pushButtona.clicked.connect(self.on_Turn_Left) 26 | self.pushButtons.clicked.connect(self.on_Back) 27 | self.pushButtond.clicked.connect(self.on_Turn_Right) 28 | self.pushButton_stop.clicked.connect(self.on_Stop) 29 | self.spinBox_speed.valueChanged.connect(self.valueChange) 30 | # 舵机控制 31 | self.pushButtonUp.clicked.connect(self.Servo_up) 32 | self.pushButtonDown.clicked.connect(self.Servo_down) 33 | self.pushButtonLeft.clicked.connect(self.Servo_left) 34 | self.pushButtonRight.clicked.connect(self.Servo_right) 35 | self.pushButtonSS.clicked.connect(self.Servo_stop) 36 | self.pushButton_follow.clicked.connect(self.fire) 37 | self.pushButton_Connect.clicked.connect(self.connect) 38 | 39 | # # 创建 socket 对象 40 | # self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 41 | # host = '10.3.141.1' 42 | # port = 2002 # 设置端口号 43 | # self.s.connect((host, port)) # 连接服务,指定主机和端口 44 | # self.timer_camera = QTimer(self) 45 | # self.cap = cv2.VideoCapture("http://10.3.141.1:8080/?action=stream") 46 | # self.timer_camera.timeout.connect(self.show_pic) 47 | # self.timer_camera.start(10) 48 | 49 | def valueChange(self): 50 | self.s.sendall(str(self.spinBox_speed.value()).encode('utf-8')) 51 | 52 | def connect(self): 53 | # 创建 socket 对象 54 | self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 55 | host = '10.3.141.1' 56 | port = 2002 # 设置端口号 57 | # host = 'http://vtmcar.cn.utools.club' 58 | # port = 2002 59 | self.s.connect((host, port)) # 连接服务,指定主机和端口 60 | self.timer_camera = QTimer(self) 61 | self.cap = cv2.VideoCapture("http://10.3.141.1:8080/?action=stream") 62 | self.timer_camera.timeout.connect(self.show_pic) 63 | self.timer_camera.start(10) 64 | 65 | 66 | 67 | def on_Forward(self): 68 | self.s.sendall('Forward'.encode('utf-8')) # 编码方式 69 | 70 | def on_Turn_Left(self): 71 | self.s.sendall('Left'.encode('utf-8')) # 编码方式 72 | 73 | def on_Turn_Right(self): 74 | self.s.sendall('Right'.encode('utf-8')) # 编码方式 75 | 76 | def on_Back(self): 77 | self.s.sendall('Back'.encode('utf-8')) # 编码方式 78 | 79 | def on_Stop(self): 80 | self.s.sendall('Stop'.encode('utf-8')) # 编码方式""" 81 | 82 | def Servo_left(self): 83 | self.s.sendall('SL'.encode('utf-8')) # 编码方式""" 84 | 85 | def Servo_right(self): 86 | self.s.sendall('SR'.encode('utf-8')) # 编码方式""" 87 | 88 | def Servo_up(self): 89 | self.s.sendall('SU'.encode('utf-8')) # 编码方式""" 90 | 91 | def Servo_down(self): 92 | self.s.sendall('SD'.encode('utf-8')) # 编码方式""" 93 | 94 | def Servo_stop(self): 95 | self.s.sendall('SS'.encode('utf-8')) # 编码方式""" 96 | 97 | 98 | def show_pic(self): 99 | success, frame = self.cap.read() 100 | if success: 101 | show = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 102 | showImage = QImage(show.data, show.shape[1], show.shape[0], frame.shape[1] * 3, QImage.Format_RGB888) 103 | self.labelView.setPixmap(QPixmap.fromImage(showImage)) 104 | self.labelView.setAlignment(Qt.AlignCenter) 105 | self.timer_camera.start(10) 106 | 107 | def fire(self): 108 | try: 109 | blue_lower = np.array([100, 43, 46]) 110 | blue_upper = np.array([124, 255, 255]) # 设置颜色区间 111 | cap = cv2.VideoCapture("http://10.3.141.1:8080/?action=stream") 112 | cap.set(3, 640) 113 | cap.set(4, 480) # 设置窗口的大小 114 | i = 0 115 | tag = None 116 | while 1: # 进入无线循环 117 | i += 1 118 | 119 | ret, frame = cap.read() # 将摄像头拍摄到的画面作为frame的值 120 | frame = cv2.GaussianBlur(frame, (5, 5), 0) # 高斯滤波GaussianBlur() 让图片模糊 121 | hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # 将图片的色域转换为HSV的样式 以便检测 122 | mask = cv2.inRange(hsv, blue_lower, blue_upper) # 设置阈值,去除背景 保留所设置的颜色 123 | 124 | mask = cv2.erode(mask, None, iterations=2) # 显示腐蚀后的图像 125 | mask = cv2.GaussianBlur(mask, (3, 3), 0) # 高斯模糊 126 | res = cv2.bitwise_and(frame, frame, mask=mask) # 图像合并 127 | 128 | cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2] # 边缘检测 129 | 130 | if i > 10 and len(cnts) > 0: # 通过边缘检测来确定所识别物体的位置信息得到相对坐标 131 | i = 0 132 | cnt = max(cnts, key=cv2.contourArea) 133 | (x, y), radius = cv2.minEnclosingCircle(cnt) 134 | cv2.circle(frame, (int(x), int(y)), int(radius), (255, 0, 255), 2) # 画出一个圆 135 | print(int(x), int(y)) 136 | print(int(radius)) 137 | 138 | if x > 490: 139 | if tag != 'r': 140 | self.s.sendall('Right'.encode('utf-8')) 141 | tag = 'r' 142 | print('right') 143 | time.sleep(0.4) 144 | self.s.sendall('Stop'.encode('utf-8')) 145 | tag = 's' 146 | elif x < 150: 147 | if tag != 'l': 148 | self.s.sendall('Left'.encode('utf-8')) 149 | tag = 'l' 150 | print('left') 151 | time.sleep(0.4) 152 | self.s.sendall('Stop'.encode('utf-8')) 153 | tag = 's' 154 | elif 40 < radius < 120: 155 | if tag != 'f': 156 | print('forward') 157 | self.s.sendall('Forward'.encode('utf-8')) 158 | tag = 'f' 159 | time.sleep(1) 160 | self.s.sendall('Stop'.encode('utf-8')) 161 | tag = 's' 162 | elif radius > 200 or radius < 40: 163 | if 'tag' != 'b': 164 | print('down') 165 | self.s.sendall('Back'.encode('utf-8')) 166 | tag = 'b' 167 | time.sleep(1) 168 | self.s.sendall('Stop'.encode('utf-8')) 169 | tag = 's' 170 | elif tag != 's': 171 | print('stop') 172 | self.s.sendall('Stop'.encode('utf-8')) 173 | tag = 's' 174 | else: 175 | pass 176 | cv2.imshow('video', frame) # 将具体的测试效果显示出来 177 | # cv2.imshow('mask',mask) 178 | # cv2.imshow('res',res) 179 | if cv2.waitKey(5) & 0xFF == 27: # 如果按了ESC就退出 当然也可以自己设置 180 | self.s.sendall('Stop'.encode('utf-8')) 181 | print('已经发送停止并且结束程序') 182 | break 183 | 184 | cap.release() 185 | cv2.destroyAllWindows() # 后面两句是常规操作,每次使用摄像头都需要这样设置一波 186 | 187 | 188 | except KeyboardInterrupt: 189 | self.s.sendall('Stop'.encode('utf-8')) 190 | print('已经发送停止并且结束程序') 191 | sys.exit() 192 | 193 | 194 | if __name__ == '__main__': 195 | app = QApplication(sys.argv) 196 | splash = QtWidgets.QSplashScreen(QtGui.QPixmap("loading.png")) 197 | splash.showMessage("正在加载", QtCore.Qt.AlignHCenter, QtCore.Qt.black) 198 | splash.show() # 显示启动界面 199 | MainWindow = fin() 200 | MainWindow.show() 201 | splash.finish(MainWindow) 202 | sys.exit(app.exec_()) 203 | -------------------------------------------------------------------------------- /computecolor.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | cv2.resizeWindow("enhanced", 640, 480) 4 | image = cv2.imread('hsv4.png') 5 | HSV = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) 6 | 7 | 8 | def getpos(event, x, y, flags, param): 9 | if event == cv2.EVENT_LBUTTONDOWN: # 定义一个鼠标左键按下去的事件 10 | print(HSV[y, x]) 11 | 12 | 13 | cv2.imshow("imageHSV", HSV) 14 | cv2.imshow('image', image) 15 | cv2.setMouseCallback("imageHSV", getpos) 16 | cv2.waitKey(0) 17 | -------------------------------------------------------------------------------- /fire_detection.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # encoding:utf-8 3 | import RPi.GPIO as GPIO 4 | import time 5 | 6 | 7 | Buzzer = 11 8 | 9 | CL = [0, 131, 147, 165, 175, 196, 211, 248] # Frequency of Low C notes 10 | 11 | CM = [0, 262, 294, 330, 350, 393, 441, 495] # Frequency of Middle C notes 12 | 13 | CH = [0, 525, 589, 661, 700, 786, 882, 990] # Frequency of High C notes 14 | 15 | song_1 = [ CM[3], CM[5], CM[6], CM[3], CM[2], CM[3], CM[5], CM[6], # Notes of song1 16 | CH[1], CM[6], CM[5], CM[1], CM[3], CM[2], CM[2], CM[3], 17 | CM[5], CM[2], CM[3], CM[3], CL[6], CL[6], CL[6], CM[1], 18 | CM[2], CM[3], CM[2], CL[7], CL[6], CM[1], CL[5] ] 19 | 20 | beat_1 = [ 1, 1, 3, 1, 1, 3, 1, 1, # Beats of song 1, 1 means 1/8 beats 21 | 1, 1, 1, 1, 1, 1, 3, 1, 22 | 1, 3, 1, 1, 1, 1, 1, 1, 23 | 1, 2, 1, 1, 1, 1, 1, 1, 24 | 1, 1, 3 ] 25 | 26 | song_2 = [ CM[1], CM[1], CM[1], CL[5], CM[3], CM[3], CM[3], CM[1], # Notes of song2 27 | CM[1], CM[3], CM[5], CM[5], CM[4], CM[3], CM[2], CM[2], 28 | CM[3], CM[4], CM[4], CM[3], CM[2], CM[3], CM[1], CM[1], 29 | CM[3], CM[2], CL[5], CL[7], CM[2], CM[1] ] 30 | 31 | beat_2 = [ 1, 1, 2, 2, 1, 1, 2, 2, # Beats of song 2, 1 means 1/8 beats 32 | 1, 1, 2, 2, 1, 1, 3, 1, 33 | 1, 2, 2, 1, 1, 2, 2, 1, 34 | 1, 2, 2, 1, 1, 3 ] 35 | pin_fire=27 36 | G = 17 37 | GPIO.setmode(GPIO.BCM) 38 | GPIO.setup(pin_fire, GPIO.IN, pull_up_down=GPIO.PUD_UP) 39 | GPIO.setup(G, GPIO.OUT) 40 | GPIO.setup(Buzzer, GPIO.OUT) # Set pins' mode is output 41 | global Buzz # Assign a global variable to replace GPIO.PWM 42 | Buzz = GPIO.PWM(Buzzer, 440) # 440 is initial frequency. 43 | Buzz.start(50) 44 | try: 45 | while True: 46 | status = GPIO.input(pin_fire) 47 | if status == True: 48 | print('没有检测到火') 49 | GPIO.output(G, False) 50 | time.sleep(0.25) 51 | else: 52 | print('检测到火灾') 53 | GPIO.output(G, True) # AIN1 54 | Buzz.ChangeFrequency(song_1[i]) # Change the frequency along the song note 55 | time.sleep(beat_1[i] * 0.5) # delay a note for beat * 0.5s 56 | if i < 10: 57 | i = i+1 58 | else: 59 | i = 0 60 | except KeyboradInterrupt: 61 | GPIO.cleanup() -------------------------------------------------------------------------------- /infrad_avoid.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | #本段代码实现树莓派智能小车的红外避障效果 4 | #代码使用的树莓派GPIO是用的BOARD编码方式。 5 | import RPi.GPIO as GPIO 6 | import time 7 | import sys 8 | 9 | SensorRight = 16 10 | SensorLeft = 12 11 | 12 | PWMA = 18 13 | AIN1 = 22 14 | AIN2 = 27 15 | 16 | PWMB = 23 17 | BIN1 = 25 18 | BIN2 = 24 19 | 20 | BtnPin = 19 21 | Gpin = 5 22 | Rpin = 6 23 | 24 | def t_up(speed,t_time): 25 | L_Motor.ChangeDutyCycle(speed) 26 | GPIO.output(AIN2,False)#AIN2 27 | GPIO.output(AIN1,True) #AIN1 28 | 29 | R_Motor.ChangeDutyCycle(speed) 30 | GPIO.output(BIN2,False)#BIN2 31 | GPIO.output(BIN1,True) #BIN1 32 | time.sleep(t_time) 33 | 34 | def t_stop(t_time): 35 | L_Motor.ChangeDutyCycle(0) 36 | GPIO.output(AIN2,False)#AIN2 37 | GPIO.output(AIN1,False) #AIN1 38 | 39 | R_Motor.ChangeDutyCycle(0) 40 | GPIO.output(BIN2,False)#BIN2 41 | GPIO.output(BIN1,False) #BIN1 42 | time.sleep(t_time) 43 | 44 | def t_down(speed,t_time): 45 | L_Motor.ChangeDutyCycle(speed) 46 | GPIO.output(AIN2,True)#AIN2 47 | GPIO.output(AIN1,False) #AIN1 48 | 49 | R_Motor.ChangeDutyCycle(speed) 50 | GPIO.output(BIN2,True)#BIN2 51 | GPIO.output(BIN1,False) #BIN1 52 | time.sleep(t_time) 53 | 54 | def t_left(speed,t_time): 55 | L_Motor.ChangeDutyCycle(speed) 56 | GPIO.output(AIN2,True)#AIN2 57 | GPIO.output(AIN1,False) #AIN1 58 | 59 | R_Motor.ChangeDutyCycle(speed) 60 | GPIO.output(BIN2,False)#BIN2 61 | GPIO.output(BIN1,True) #BIN1 62 | time.sleep(t_time) 63 | 64 | def t_right(speed,t_time): 65 | L_Motor.ChangeDutyCycle(speed) 66 | GPIO.output(AIN2,False)#AIN2 67 | GPIO.output(AIN1,True) #AIN1 68 | 69 | R_Motor.ChangeDutyCycle(speed) 70 | GPIO.output(BIN2,True)#BIN2 71 | GPIO.output(BIN1,False) #BIN1 72 | time.sleep(t_time) 73 | 74 | def keysacn(): 75 | val = GPIO.input(BtnPin) 76 | while GPIO.input(BtnPin) == False: 77 | val = GPIO.input(BtnPin) 78 | while GPIO.input(BtnPin) == True: 79 | time.sleep(0.01) 80 | val = GPIO.input(BtnPin) 81 | if val == True: 82 | GPIO.output(Rpin,1) 83 | while GPIO.input(BtnPin) == False: 84 | GPIO.output(Rpin,0) 85 | else: 86 | GPIO.output(Rpin,0) 87 | 88 | def setup(): 89 | GPIO.setwarnings(False) 90 | GPIO.setmode(GPIO.BCM) # Numbers GPIOs by physical location 91 | GPIO.setup(Gpin, GPIO.OUT) # Set Green Led Pin mode to output 92 | GPIO.setup(Rpin, GPIO.OUT) # Set Red Led Pin mode to output 93 | GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V) 94 | GPIO.setup(SensorRight,GPIO.IN) 95 | GPIO.setup(SensorLeft,GPIO.IN) 96 | 97 | GPIO.setup(AIN2,GPIO.OUT) 98 | GPIO.setup(AIN1,GPIO.OUT) 99 | GPIO.setup(PWMA,GPIO.OUT) 100 | 101 | GPIO.setup(BIN1,GPIO.OUT) 102 | GPIO.setup(BIN2,GPIO.OUT) 103 | GPIO.setup(PWMB,GPIO.OUT) 104 | 105 | if __name__ == '__main__': 106 | setup() 107 | #keysacn() 108 | L_Motor= GPIO.PWM(PWMA,100) 109 | L_Motor.start(0) 110 | R_Motor = GPIO.PWM(PWMB,100) 111 | R_Motor.start(0) 112 | try: 113 | while True: 114 | SR_2 = GPIO.input(SensorRight) 115 | SL_2 = GPIO.input(SensorLeft) 116 | if SL_2 == True and SR_2 == True: 117 | print("t_up") 118 | t_up(20,0) 119 | elif SL_2 == True and SR_2 ==False: 120 | print("Left") 121 | t_left(30,0) 122 | elif SL_2==False and SR_2 ==True: 123 | print("Right") 124 | t_right(30,0) 125 | else: 126 | t_stop(0.3) 127 | t_down(30,0.4) 128 | t_left(30,0.5) 129 | except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. 130 | t_stop(0) 131 | write(0,90) 132 | GPIO.cleanup() 133 | -------------------------------------------------------------------------------- /passive_buzzer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #--------------------------------------------------- 3 | # 4 | # This is a program for Passive Buzzer Module 5 | # It will play simple songs. 6 | # You could try to make songs by youselves! 7 | # 8 | # Passive buzzer Pi 9 | # VCC ----------------- 3.3V 10 | # GND ------------------ GND 11 | # SIG ---------------- Pin 11 12 | # 13 | #--------------------------------------------------- 14 | 15 | import RPi.GPIO as GPIO 16 | import time 17 | 18 | Buzzer = 11 19 | 20 | CL = [0, 131, 147, 165, 175, 196, 211, 248] # Frequency of Low C notes 21 | 22 | CM = [0, 262, 294, 330, 350, 393, 441, 495] # Frequency of Middle C notes 23 | 24 | CH = [0, 525, 589, 661, 700, 786, 882, 990] # Frequency of High C notes 25 | 26 | song_1 = [ CM[3], CM[5], CM[6], CM[3], CM[2], CM[3], CM[5], CM[6], # Notes of song1 27 | CH[1], CM[6], CM[5], CM[1], CM[3], CM[2], CM[2], CM[3], 28 | CM[5], CM[2], CM[3], CM[3], CL[6], CL[6], CL[6], CM[1], 29 | CM[2], CM[3], CM[2], CL[7], CL[6], CM[1], CL[5] ] 30 | 31 | beat_1 = [ 1, 1, 3, 1, 1, 3, 1, 1, # Beats of song 1, 1 means 1/8 beats 32 | 1, 1, 1, 1, 1, 1, 3, 1, 33 | 1, 3, 1, 1, 1, 1, 1, 1, 34 | 1, 2, 1, 1, 1, 1, 1, 1, 35 | 1, 1, 3 ] 36 | 37 | song_2 = [ CM[1], CM[1], CM[1], CL[5], CM[3], CM[3], CM[3], CM[1], # Notes of song2 38 | CM[1], CM[3], CM[5], CM[5], CM[4], CM[3], CM[2], CM[2], 39 | CM[3], CM[4], CM[4], CM[3], CM[2], CM[3], CM[1], CM[1], 40 | CM[3], CM[2], CL[5], CL[7], CM[2], CM[1] ] 41 | 42 | beat_2 = [ 1, 1, 2, 2, 1, 1, 2, 2, # Beats of song 2, 1 means 1/8 beats 43 | 1, 1, 2, 2, 1, 1, 3, 1, 44 | 1, 2, 2, 1, 1, 2, 2, 1, 45 | 1, 2, 2, 1, 1, 3 ] 46 | 47 | def setup(): 48 | GPIO.setwarnings(False) 49 | GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location 50 | GPIO.setup(Buzzer, GPIO.OUT) # Set pins' mode is output 51 | global Buzz # Assign a global variable to replace GPIO.PWM 52 | Buzz = GPIO.PWM(Buzzer, 440) # 440 is initial frequency. 53 | Buzz.start(50) # Start Buzzer pin with 50% duty ration 54 | 55 | def loop(): 56 | while True: 57 | print('\n Playing song 1...') 58 | for i in range(1, len(song_1)): # Play song 1 59 | Buzz.ChangeFrequency(song_1[i]) # Change the frequency along the song note 60 | time.sleep(beat_1[i] * 0.5) # delay a note for beat * 0.5s 61 | time.sleep(1) # Wait a second for next song. 62 | 63 | print('\n\n Playing song 2...') 64 | for i in range(1, len(song_2)): # Play song 1 65 | Buzz.ChangeFrequency(song_2[i]) # Change the frequency along the song note 66 | time.sleep(beat_2[i] * 0.5) # delay a note for beat * 0.5s 67 | 68 | def destory(): 69 | Buzz.stop() # Stop the buzzer 70 | GPIO.output(Buzzer, 1) # Set Buzzer pin to High 71 | GPIO.cleanup() # Release resource 72 | 73 | if __name__ == '__main__': # Program start from here 74 | setup() 75 | try: 76 | loop() 77 | except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. 78 | destory() 79 | -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | # 导入必要的包 2 | import socket,sys,os 3 | import time 4 | 5 | # import wiringpi,time,multiprocessing 6 | import RPi.GPIO as GPIO 7 | from Adafruit_PWM_Servo_Driver import PWM 8 | 9 | pwm = PWM(0x40,debug = False) 10 | 11 | servoMin = 150 # Min pulse length out of 4096 12 | servoMax = 600 # Max pulse length out of 4096 13 | 14 | def setServoPulse(channel, pulse): 15 | pulseLength = 1000000.0 # 1,000,000 us per second 16 | pulseLength /= 50.0 # 60 Hz 17 | print("%d us per period" % pulseLength) 18 | pulseLength /= 4096.0 # 12 bits of resolution 19 | print("%d us per bit" % pulseLength) 20 | pulse *= 1000.0 21 | pulse /= (pulseLength*1.0) 22 | # pwmV=int(pluse) 23 | print("pluse: %f " % (pulse)) 24 | pwm.setPWM(channel, 0, int(pulse)) 25 | 26 | 27 | #Angle to PWM 28 | def write(servonum,x): 29 | y=x/90.0+0.5 30 | y=max(y,0.5) 31 | y=min(y,2.5) 32 | setServoPulse(servonum,y) 33 | 34 | pwm.setPWMFreq(50) # Set frequency to 50 Hz 35 | 36 | PWMA = 18 37 | AIN1 = 22 38 | AIN2 = 27 39 | 40 | PWMB = 23 41 | BIN1 = 25 42 | BIN2 = 24 43 | 44 | GPIO.setwarnings(False) 45 | GPIO.setmode(GPIO.BCM) 46 | GPIO.setup(AIN2,GPIO.OUT) 47 | GPIO.setup(AIN1,GPIO.OUT) 48 | GPIO.setup(PWMA,GPIO.OUT) 49 | 50 | GPIO.setup(BIN1,GPIO.OUT) 51 | GPIO.setup(BIN2,GPIO.OUT) 52 | GPIO.setup(PWMB,GPIO.OUT) 53 | 54 | L_Motor= GPIO.PWM(PWMA,100) 55 | L_Motor.start(0) 56 | 57 | R_Motor = GPIO.PWM(PWMB,100) 58 | R_Motor.start(0) 59 | 60 | 61 | 62 | # 定义小车类及方法 63 | class Car(object): 64 | def __init__(self): 65 | self.t_stop(2) 66 | 67 | def t_up(self, speed, t_time): 68 | L_Motor.ChangeDutyCycle(speed) 69 | GPIO.output(AIN2,False)#AIN2 70 | GPIO.output(AIN1,True) #AIN1 71 | 72 | R_Motor.ChangeDutyCycle(speed) 73 | GPIO.output(BIN2,False)#BIN2 74 | GPIO.output(BIN1,True) #BIN1 75 | time.sleep(t_time) 76 | 77 | def t_stop(self,t_time): 78 | L_Motor.ChangeDutyCycle(0) 79 | GPIO.output(AIN2,False)#AIN2 80 | GPIO.output(AIN1,False) #AIN1 81 | 82 | R_Motor.ChangeDutyCycle(0) 83 | GPIO.output(BIN2,False)#BIN2 84 | GPIO.output(BIN1,False) #BIN1 85 | time.sleep(t_time) 86 | 87 | def t_down(self,speed,t_time): 88 | L_Motor.ChangeDutyCycle(speed) 89 | GPIO.output(AIN2,True)#AIN2 90 | GPIO.output(AIN1,False) #AIN1 91 | 92 | R_Motor.ChangeDutyCycle(speed) 93 | GPIO.output(BIN2,True)#BIN2 94 | GPIO.output(BIN1,False) #BIN1 95 | time.sleep(t_time) 96 | 97 | def t_left(self,speed,t_time): 98 | L_Motor.ChangeDutyCycle(speed) 99 | GPIO.output(AIN2,True)#AIN2 100 | GPIO.output(AIN1,False) #AIN1 101 | 102 | R_Motor.ChangeDutyCycle(speed) 103 | GPIO.output(BIN2,False)#BIN2 104 | GPIO.output(BIN1,True) #BIN1 105 | time.sleep(t_time) 106 | 107 | def t_right(self,speed,t_time): 108 | L_Motor.ChangeDutyCycle(speed) 109 | GPIO.output(AIN2,False)#AIN2 110 | GPIO.output(AIN1,True) #AIN1 111 | 112 | R_Motor.ChangeDutyCycle(speed) 113 | GPIO.output(BIN2,True)#BIN2 114 | GPIO.output(BIN1,False) #BIN1 115 | time.sleep(t_time) 116 | 117 | def Servo_left(self,servo_lr): 118 | if servo_lr>170: 119 | servo_lr = 175 120 | else : 121 | servo_lr += 10 122 | write(1, servo_lr) 123 | return servo_lr 124 | 125 | def Servo_right(self,servo_lr): 126 | if servo_lr<30: 127 | servo_lr = 20 128 | else : 129 | servo_lr -= 10 130 | write(1, servo_lr) 131 | 132 | return servo_lr 133 | 134 | 135 | def Servo_up(self,servo_ud): 136 | if servo_ud<5: 137 | servo_ud = 0 138 | else : 139 | servo_ud -= 5 140 | write(2, servo_ud) 141 | return servo_ud 142 | 143 | 144 | def Servo_down(self,servo_ud): 145 | if servo_ud>35: 146 | servo_ud = 40 147 | else : 148 | servo_ud += 5 149 | write(2, servo_ud) 150 | 151 | return servo_ud 152 | 153 | 154 | def Servo_stop(self): 155 | pwm.setsleep() 156 | 157 | 158 | # 使用 socket 进行连接 159 | def rec_msg(car): 160 | servo_lr = 90 161 | servo_ud = 0 162 | speed = 30 163 | serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 164 | host = '0.0.0.0' 165 | port = 2001 # 设置端口号 166 | print(host) 167 | serversocket.bind((host, port)) 168 | serversocket.listen() 169 | clientsocket, addr = serversocket.accept() 170 | 171 | while True: 172 | rec_msg = clientsocket.recv(1024).decode('utf-8') 173 | print(rec_msg) 174 | if rec_msg == "Forward": 175 | car.t_up(speed,0) 176 | elif rec_msg == "Back": 177 | car.t_down(speed,0) 178 | elif rec_msg == "Left": 179 | car.t_left(30,0) 180 | elif rec_msg == "Right": 181 | car.t_right(30,0) 182 | elif rec_msg == "Stop": 183 | car.t_stop(0) 184 | elif rec_msg == "SL": 185 | servo_lr = car.Servo_left(servo_lr) 186 | elif rec_msg == "SR": 187 | servo_lr = car.Servo_right(servo_lr) 188 | elif rec_msg == "SU": 189 | servo_ud = car.Servo_up(servo_ud) 190 | elif rec_msg == "SD": 191 | servo_ud =car.Servo_down(servo_ud) 192 | elif rec_msg == "SS": 193 | car.Servo_stop(0) 194 | elif rec_msg.isdigit(): 195 | speed = eval(rec_msg) 196 | 197 | 198 | # 主函数 199 | if __name__ == "__main__": 200 | car = Car() 201 | rec_msg(car) -------------------------------------------------------------------------------- /testmjpg - 2.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np # 导入库 3 | import time 4 | import socket 5 | import sys 6 | 7 | 8 | # 创建 socket 对象 9 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 10 | host = '10.3.141.1' 11 | port = 2001 # 设置端口号 12 | s.connect((host, port)) # 连接服务,指定主机和端口 13 | 14 | try: 15 | black_lower = np.array([110, 64, 100]) 16 | black_upper = np.array([125, 255, 255]) # 设置颜色区间 17 | blue_lower = np.array([35, 64, 128]) 18 | blue_upper = np.array([55, 255, 255]) # 设置颜色区间 19 | cap = cv2.VideoCapture("http://10.3.141.1:8080/?action=stream") 20 | cap.set(3, 640) 21 | cap.set(4, 480) # 设置窗口的大小 22 | 23 | tag = None 24 | while 1: # 进入无线循环 25 | t_start = time.time() 26 | 27 | ret, frame = cap.read() # 将摄像头拍摄到的画面作为frame的值 28 | frame = cv2.GaussianBlur(frame, (5, 5), 0) # 高斯滤波GaussianBlur() 让图片模糊 29 | hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # 将图片的色域转换为HSV的样式 以便检测 30 | mask = cv2.inRange(hsv, blue_lower, blue_upper) # 设置阈值,去除背景 保留所设置的颜色 31 | mask2 = cv2.inRange(hsv, black_lower, black_upper) # 设置阈值,去除背景 保留所设置的颜色 32 | 33 | mask = cv2.erode(mask, None, iterations=2) # 显示腐蚀后的图像 34 | mask = cv2.GaussianBlur(mask, (3, 3), 0) # 高斯模糊 35 | mask2 = cv2.erode(mask2, None, iterations=2) # 显示腐蚀后的图像 36 | mask2 = cv2.GaussianBlur(mask2, (3, 3), 0) # 高斯模糊 37 | res = cv2.bitwise_and(frame, frame, mask=mask) # 图像合并 38 | res2 = cv2.bitwise_and(frame, frame, mask=mask2) # 图像合并 39 | cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2] # 边缘检测 40 | cnts2 = cv2.findContours(mask2.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2] # 边缘检测 41 | if len(cnts) > 0: # 通过边缘检测来确定所识别物体的位置信息得到相对坐标 42 | cnt = max(cnts, key=cv2.contourArea) 43 | (x, y), radius = cv2.minEnclosingCircle(cnt) 44 | cv2.circle(frame, (int(x), int(y)), int(radius), (255, 0, 255), 2) # 画出一个圆 45 | print(int(x), int(y)) 46 | print(int(radius)) 47 | 48 | if x > 490: 49 | if tag != 'r': 50 | s.sendall('Right'.encode('utf-8')) 51 | tag = 'r' 52 | print('right') 53 | elif x < 150: 54 | if tag != 'l': 55 | s.sendall('Left'.encode('utf-8')) 56 | tag = 'l' 57 | print('left') 58 | elif radius < 120: 59 | if tag != 'f': 60 | print('forward') 61 | s.sendall('Forward'.encode('utf-8')) 62 | tag = 'f' 63 | elif radius > 200: 64 | if 'tag' != 'b': 65 | print('down') 66 | s.sendall('Back'.encode('utf-8')) 67 | tag = 'b' 68 | elif tag != 's': 69 | print('stop') 70 | s.sendall('Stop'.encode('utf-8')) 71 | tag = 's' 72 | elif len(cnts2) > 0: # 通过边缘检测来确定所识别物体的位置信息得到相对坐标 73 | cnt = max(cnts2, key=cv2.contourArea) 74 | (x, y), radius = cv2.minEnclosingCircle(cnt) 75 | cv2.circle(frame, (int(x), int(y)), int(radius), (255, 0, 255), 2) # 画出一个圆 76 | print(int(x), int(y)) 77 | print(int(radius)) 78 | 79 | if x > 490: 80 | if tag != 'r': 81 | s.sendall('Right'.encode('utf-8')) 82 | tag = 'r' 83 | print('right') 84 | elif x < 150: 85 | if tag != 'l': 86 | s.sendall('Left'.encode('utf-8')) 87 | tag = 'l' 88 | print('left') 89 | elif radius < 120: 90 | if tag != 'f': 91 | print('forward') 92 | s.sendall('Forward'.encode('utf-8')) 93 | tag = 'f' 94 | elif radius > 200: 95 | if 'tag' != 'b': 96 | print('down') 97 | s.sendall('Back'.encode('utf-8')) 98 | tag = 'b' 99 | elif tag != 's': 100 | print('stop') 101 | s.sendall('Stop'.encode('utf-8')) 102 | tag = 's' 103 | else: 104 | print('stop') 105 | s.sendall('Stop'.encode('utf-8')) 106 | tag = 's' 107 | cv2.imshow('video', frame) # 将具体的测试效果显示出来 108 | cv2.imshow('mask', mask) 109 | cv2.imshow('res', res) 110 | if cv2.waitKey(5) & 0xFF == 27: # 如果按了ESC就退出 当然也可以自己设置 111 | s.sendall('Stop'.encode('utf-8')) 112 | print('已经发送停止并且结束程序') 113 | break 114 | 115 | mfps = 1 / (time.time() - t_start) 116 | print('FPS', mfps) 117 | 118 | cap.release() 119 | cv2.destroyAllWindows() # 后面两句是常规操作,每次使用摄像头都需要这样设置一波 120 | 121 | 122 | except KeyboardInterrupt: 123 | s.sendall('Stop'.encode('utf-8')) 124 | print('已经发送停止并且结束程序') 125 | sys.exit() 126 | -------------------------------------------------------------------------------- /testmjpg.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np # 导入库 3 | import time 4 | import socket 5 | import sys 6 | 7 | 8 | # 创建 socket 对象 9 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 10 | host = '10.3.141.1' 11 | port = 2001 # 设置端口号 12 | s.connect((host, port)) # 连接服务,指定主机和端口 13 | 14 | try: 15 | blue_lower = np.array([100, 43, 46]) 16 | blue_upper = np.array([124, 255, 255]) # 设置颜色区间 17 | cap = cv2.VideoCapture("http://10.3.141.1:8080/?action=stream") 18 | cap.set(3, 640) 19 | cap.set(4, 480) # 设置窗口的大小 20 | 21 | tag = None 22 | while 1: # 进入无线循环 23 | t_start = time.time() 24 | 25 | ret, frame = cap.read() # 将摄像头拍摄到的画面作为frame的值 26 | frame = cv2.GaussianBlur(frame, (5, 5), 0) # 高斯滤波GaussianBlur() 让图片模糊 27 | hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # 将图片的色域转换为HSV的样式 以便检测 28 | mask = cv2.inRange(hsv, blue_lower, blue_upper) # 设置阈值,去除背景 保留所设置的颜色 29 | 30 | mask = cv2.erode(mask, None, iterations=2) # 显示腐蚀后的图像 31 | mask = cv2.GaussianBlur(mask, (3, 3), 0) # 高斯模糊 32 | res = cv2.bitwise_and(frame, frame, mask=mask) # 图像合并 33 | 34 | cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2] # 边缘检测 35 | 36 | if len(cnts) > 0: # 通过边缘检测来确定所识别物体的位置信息得到相对坐标 37 | cnt = max(cnts, key=cv2.contourArea) 38 | (x, y), radius = cv2.minEnclosingCircle(cnt) 39 | cv2.circle(frame, (int(x), int(y)), int(radius), (255, 0, 255), 2) # 画出一个圆 40 | print(int(x), int(y)) 41 | print(int(radius)) 42 | 43 | if x > 490: 44 | if tag != 'r': 45 | s.sendall('Right'.encode('utf-8')) 46 | tag = 'r' 47 | print('right') 48 | # time.sleep(0.4) 49 | # s.sendall('Stop'.encode('utf-8')) 50 | # tag = 's' 51 | elif x < 150: 52 | if tag != 'l': 53 | s.sendall('Left'.encode('utf-8')) 54 | tag = 'l' 55 | print('left') 56 | # time.sleep(0.4) 57 | # s.sendall('Stop'.encode('utf-8')) 58 | # tag = 's' 59 | elif radius < 120: 60 | if tag != 'f': 61 | print('forward') 62 | s.sendall('Forward'.encode('utf-8')) 63 | tag = 'f' 64 | # time.sleep(1) 65 | # s.sendall('Stop'.encode('utf-8')) 66 | # tag = 's' 67 | elif radius > 200: 68 | if 'tag' != 'b': 69 | print('down') 70 | s.sendall('Back'.encode('utf-8')) 71 | tag = 'b' 72 | # time.sleep(1) 73 | # s.sendall('Stop'.encode('utf-8')) 74 | # tag = 's' 75 | elif tag != 's': 76 | print('stop') 77 | s.sendall('Stop'.encode('utf-8')) 78 | tag = 's' 79 | else: 80 | print('stop') 81 | s.sendall('Stop'.encode('utf-8')) 82 | tag = 's' 83 | cv2.imshow('video', frame) # 将具体的测试效果显示出来 84 | # cv2.imshow('mask',mask) 85 | # cv2.imshow('res',res) 86 | if cv2.waitKey(5) & 0xFF == 27: # 如果按了ESC就退出 当然也可以自己设置 87 | s.sendall('Stop'.encode('utf-8')) 88 | print('已经发送停止并且结束程序') 89 | break 90 | 91 | mfps = 1 / (time.time() - t_start) 92 | print('FPS', mfps) 93 | 94 | 95 | cap.release() 96 | cv2.destroyAllWindows() # 后面两句是常规操作,每次使用摄像头都需要这样设置一波 97 | 98 | 99 | except KeyboardInterrupt: 100 | s.sendall('Stop'.encode('utf-8')) 101 | print('已经发送停止并且结束程序') 102 | sys.exit() 103 | -------------------------------------------------------------------------------- /tracking_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | #本段代码实现树莓派智能小车的红外避障效果 4 | #代码使用的树莓派GPIO是用的BOARD编码方式。 5 | import RPi.GPIO as GPIO 6 | import time 7 | import sys 8 | 9 | T_SensorRight = 26 10 | T_SensorLeft = 13 11 | 12 | PWMA = 18 13 | AIN1 = 22 14 | AIN2 = 27 15 | 16 | PWMB = 23 17 | BIN1 = 25 18 | BIN2 = 24 19 | 20 | T_SM = 19 21 | Gpin = 5 22 | Rpin = 6 23 | 24 | def t_up(speed,t_time): 25 | L_Motor.ChangeDutyCycle(speed) 26 | GPIO.output(AIN2,False)#AIN2 27 | GPIO.output(AIN1,True) #AIN1 28 | 29 | R_Motor.ChangeDutyCycle(speed) 30 | GPIO.output(BIN2,False)#BIN2 31 | GPIO.output(BIN1,True) #BIN1 32 | time.sleep(t_time) 33 | 34 | def t_stop(t_time): 35 | L_Motor.ChangeDutyCycle(0) 36 | GPIO.output(AIN2,False)#AIN2 37 | GPIO.output(AIN1,False) #AIN1 38 | 39 | R_Motor.ChangeDutyCycle(0) 40 | GPIO.output(BIN2,False)#BIN2 41 | GPIO.output(BIN1,False) #BIN1 42 | time.sleep(t_time) 43 | 44 | def t_down(speed,t_time): 45 | L_Motor.ChangeDutyCycle(speed) 46 | GPIO.output(AIN2,True)#AIN2 47 | GPIO.output(AIN1,False) #AIN1 48 | 49 | R_Motor.ChangeDutyCycle(speed) 50 | GPIO.output(BIN2,True)#BIN2 51 | GPIO.output(BIN1,False) #BIN1 52 | time.sleep(t_time) 53 | 54 | def t_left(speed,t_time): 55 | L_Motor.ChangeDutyCycle(speed) 56 | GPIO.output(AIN2,True)#AIN2 57 | GPIO.output(AIN1,False) #AIN1 58 | 59 | R_Motor.ChangeDutyCycle(speed) 60 | GPIO.output(BIN2,False)#BIN2 61 | GPIO.output(BIN1,True) #BIN1 62 | time.sleep(t_time) 63 | 64 | def t_right(speed,t_time): 65 | L_Motor.ChangeDutyCycle(speed) 66 | GPIO.output(AIN2,False)#AIN2 67 | GPIO.output(AIN1,True) #AIN1 68 | 69 | R_Motor.ChangeDutyCycle(speed) 70 | GPIO.output(BIN2,True)#BIN2 71 | GPIO.output(BIN1,False) #BIN1 72 | time.sleep(t_time) 73 | 74 | def keysacn(): 75 | val = GPIO.input(BtnPin) 76 | while GPIO.input(BtnPin) == False: 77 | val = GPIO.input(BtnPin) 78 | while GPIO.input(BtnPin) == True: 79 | time.sleep(0.01) 80 | val = GPIO.input(BtnPin) 81 | if val == True: 82 | GPIO.output(Rpin,1) 83 | while GPIO.input(BtnPin) == False: 84 | GPIO.output(Rpin,0) 85 | else: 86 | GPIO.output(Rpin,0) 87 | 88 | def setup(): 89 | GPIO.setwarnings(False) 90 | GPIO.setmode(GPIO.BCM) # Numbers GPIOs by physical location 91 | GPIO.setup(Gpin, GPIO.OUT) # Set Green Led Pin mode to output 92 | GPIO.setup(Rpin, GPIO.OUT) # Set Red Led Pin mode to output 93 | #GPIO.setup(T_SM,GPIO.IN) 94 | #GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V) 95 | GPIO.setup(T_SensorRight,GPIO.IN) 96 | GPIO.setup(T_SensorLeft,GPIO.IN) 97 | 98 | GPIO.setup(AIN2,GPIO.OUT) 99 | GPIO.setup(AIN1,GPIO.OUT) 100 | GPIO.setup(PWMA,GPIO.OUT) 101 | 102 | GPIO.setup(BIN1,GPIO.OUT) 103 | GPIO.setup(BIN2,GPIO.OUT) 104 | GPIO.setup(PWMB,GPIO.OUT) 105 | 106 | if __name__ == '__main__': 107 | setup() 108 | # keysacn() 109 | L_Motor= GPIO.PWM(PWMA,100) 110 | L_Motor.start(0) 111 | R_Motor = GPIO.PWM(PWMB,100) 112 | R_Motor.start(0) 113 | print('111') 114 | try: 115 | while True: 116 | SR = GPIO.input(T_SensorRight) 117 | SL = GPIO.input(T_SensorLeft) 118 | 119 | 120 | if SL == False and SR == False: 121 | print("t_up") 122 | t_up(40,0) 123 | elif SL == True and SR ==False: 124 | print("Left") 125 | t_left(50,0) 126 | 127 | elif SL==False and SR ==True: 128 | print("Rhgit") 129 | t_right(50,0) 130 | else: 131 | t_stop(0) 132 | except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. 133 | t_stop(0) 134 | GPIO.cleanup() 135 | --------------------------------------------------------------------------------