目录
前言
一、APICloud是什么?
二、设计步骤
APP设计
main.html
Wifi_Control.html
Car_Control.html
jetson nano Python代码设计
image_socket.py
运行代码
运行APICloud APP代码
总结
暑假的时候想自己做一个图传APP,也就是把摄像头拍摄到的图像显示在手机上,查阅资料发现APICloud挺好用的,所以就研究了半个月自制了一个简易APP,废话不多说,上源码链接:
APICloud+jetson nano+websocket +OpenCV图传APP.rar
需要的朋友可以下载。
APICloud是一个高性能多端开发技术快速开发企业级应用程序的低代码开发平台
一套代码同时生成Android、iOS、小程序、Web等多端应用,非常实用。
官网下载链接:APICloud Studio3下载
设计好的页面可以在右侧实时预览,这一点我觉得很不错。
title
AlphaBot
蓝牙控制
Wifi控制
QQ:3075221401
CSDN@静·无羡
AJJFirstAPP
我的APP很大你要忍一下
title
AlphaBot
IP 地址:
控制端口:
连接
QQ:3075221401
CSDN@静·无羡
AJJFirstAPP
我的APP很大你要忍一下
title
Stop
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from websocket_server import WebsocketServer
import threading
import cv2
import base64
import time
import subprocess
time.sleep(5)
cmd = "hostname -I | cut -d\' \' -f1"
host = subprocess.check_output(cmd,shell = True )
print(host)
# Called for every client connecting (after handshake)
def new_client(client, server):
print("got connection from ",client['address'] )
# 发送给所有的连接
server.send_message_to_all("Hey all, a new client has joined us")
# Called for every client disconnecting
def client_left(client, server):
print("Client disconnected!" )
# Called when a client sends a message
def message_received(client, server, message):
if len(message) > 200:
message = message[:200]+'..'
print("Client(%d) said: %s" % (client['id'], message))
# 发送给所有的连接
#server.send_message_to_all(message)
def vedio_thread2(n):
cap = cv2.VideoCapture(0)
width = 640
height = 480
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
while(True):
ret, img_bgr = cap.read()
if img_bgr is None:
print('lose image_value')
else:
frame = cv2.flip(img_bgr, 1)
image = cv2.imencode('.jpg', frame)[1]
base64_data = base64.b64encode(image)
s = base64_data.decode()
#cv2.imshow("video", frame)
server.send_message_to_all('data:image/jpeg;base64,%s'%s)
cv2.waitKey(50)
time.sleep(0.05)
def vedio_thread1(n):
print('send')
while True:
if len(server.clients)>0:
image = cv2.imencode('.jpg', frame)[1]
base64_data = base64.b64encode(image)
s = base64_data.decode()
#print('data:image/jpeg;base64,%s'%s)
#server.send_message_to_all('data:image/jpeg;base64,%s'%s)
time.sleep(0.05)
def from_camera():
thread1 = threading.Thread(target=vedio_thread1, args=(1,))
thread1.setDaemon(True)
thread1.start()
thread2 = threading.Thread(target=vedio_thread2, args=(1,))
thread2.setDaemon(True)
thread2.start()
print('start')
print('server is running....')
# Server Port
port=8080
# 创建Websocket Server
server = WebsocketServer(port,host)
from_camera()
# 有设备连接上了
server.set_fn_new_client(new_client)
# 断开连接
server.set_fn_client_left(client_left)
# 接收到信息
server.set_fn_message_received(message_received)
# 开始监听
server.run_forever()
手机下载好AppLoader,官方下载链接:AppLoader,通过数据线连接上电脑并开启调试模式,右击项目点击USB同步
项目编译完成后会显示可连接设备:
点击选择手机设备,手机就会自动打开AppLoader进入APP界面:
确保nano和手机连接同一个网络,在nano上运行image_socket.py:
由图可以看出nano的IP地址为192.168.0.102,代码中端口设置为8080
APP点击WIFI控制,输入IP地址和端口后点击连接,就可以在手机APP上看到nano摄像头采集的图像了。
虽然花了半个月时间才搞定,但是这次也是学习到了不少东西,嘿嘿,源代码已经上传到CSDN了,有钱的捧个钱场哈,当然想白嫖的同学可以在评论区留下邮箱,我有空就会发。