PC端环境和代码
1、先测试代码,缺啥安装啥模块:
测试环境 ubuntu-16.04-desktop-amd64
python2.7
sudo pip install pygame
注意要用root权限
pip安装OpenCV
sudo pip install opencv-python
一个个测试太慢,直接打开python,复制粘贴import的库
import socket
import time
import pygame
#import cv2.cv as cv
import Image, StringIO
import threading
import cv2
import numpy as np
就差Image模块了,(Ubuntu)
sudo pip install Image
或者安装(树莓派)
sudo pip install pillow
安装完成最后再测一遍,还是报错,
把import Image替换成"import PIL.Image",就可以导入了
打开PC端代码PC.py,把import Image替换成"import PIL.Image",凡是用到Image的都修改成PIL.Image(前提你的安装pillow(PIL))
最终PC.py:
#!/usr/bin/env python
import socket
import time
import pygame
#import cv2.cv as cv
import PIL.Image
import StringIO
import threading
import cv2
import numpy as np
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('192.168.31.118',9004))
pygame.init()
W, H = 320, 240
screen = pygame.display.set_mode((W, H))
clock = pygame.time.Clock()
running = True
command_to_send=0
command_last=0
laser_control = False
while running:
command_last=command_to_send
for event in pygame.event.get():
if event.type == pygame.QUIT:
command_to_send=5
running = False
elif event.type == pygame.KEYUP:
command_to_send=0
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
command_to_send=1
elif event.key == pygame.K_DOWN:
command_to_send=2
elif event.key == pygame.K_LEFT:
command_to_send=3
elif event.key == pygame.K_RIGHT:
command_to_send=4
if(command_to_send!=command_last):
sock.send(str(command_to_send))
clock.tick(50)
sock.close()
if __name__ == '__main__':
main()
树莓派端环境和代码:
先打开python,测试库缺漏情况:
小车部分功能:
import socket
import sys
import threading
import random
import os
import time
import struct
import serial
完整功能库:
import socket
import sys
import threading
import random
import os
import time
import struct
import serial
import cv
import cv2
import PIL.Image
import StringIO
import numpy as np
from voice_engine.source import Source
from voice_engine.channel_picker import ChannelPicker
from voice_engine.doa_respeaker_4mic_array import DOA
from pixels import pixels
import datetime
部分功能完全通过:
最终功能语音、图像方面的库有缺漏:
测试部分功能代码:
单个文件可以通过VNC直接发送,多个文件打包成zip再通过VNC发送到树莓派3B+;