五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

pyserial串口讀取esp32-cam攝像頭

2020-08-26 13:28 作者:學(xué)的很雜的一個(gè)人  | 我要投稿

講解過程視頻訪問網(wǎng)址:https://www.bilibili.com/video/BV13A411n78H/

esp32-cam的引腳連接表:


直接上代碼:

1、esp32-cam(arduino下位機(jī)代碼)

#////////////////////////////////////////////////////////////////////////////////////////////

#include "esp_camera.h"

void setup() {
Serial.begin(115200);//傳口速率
Serial.println();//僅輸出一個(gè)回車和換行符

camera_config_t config1;
//config1.ledc_channel = 4;
config1.pin_d0 = 5;
config1.pin_d1 = 18;
config1.pin_d2 = 19;
config1.pin_d3 = 21;
config1.pin_d4 = 36;
config1.pin_d5 = 39;
config1.pin_d6 = 34;
config1.pin_d7 = 35;
config1.pin_xclk = 0;
config1.pin_pclk = 22;
config1.pin_vsync = 25;
config1.pin_href = 23;
config1.pin_sscb_sda = 26;
config1.pin_sscb_scl = 27;
config1.pin_pwdn = 32;
config1.pin_reset = 15;
config1.xclk_freq_hz = 20000000;
config1.pixel_format = PIXFORMAT_JPEG;
?
// if PSRAM IC present, init with UXGA resolution and higher JPEG quality
//????????????????????? for larger pre-allocated frame buffer.
if(psramFound()){
? config1.frame_size = FRAMESIZE_UXGA;
? config1.jpeg_quality = 10;
? config1.fb_count = 2;
} else {
? config1.frame_size = FRAMESIZE_SVGA;
? config1.jpeg_quality = 12;
? config1.fb_count = 1;
}


// camera init
esp_err_t err = esp_camera_init(&config1);//攝像頭初始化
if (err != ESP_OK) {//攝像頭初始化失敗,則打印消息并終止程序
? Serial.printf("Camera init failed with error 0x%x", err);
? return;
}

?? Serial.printf("camera is runing\n");

sensor_t *s = esp_camera_sensor_get();//獲取調(diào)整圖像接口
s->set_framesize(s, FRAMESIZE_VGA);//更改幀尺寸
//s->set_quality(s, 10);//設(shè)置品質(zhì)10


//acquire a frame獲取圖像,查看是否改變
camera_fb_t * fb = esp_camera_fb_get();

if (!fb)
{
??? Serial.print( "Camera capture failed");
}
else
{
??? Serial.printf("width:%d, height:%d, format:%d, len:%d\r\n", fb->width, fb->height, fb->format, fb->len);//輸出width:640, height:480, format:3, len:30805;尺寸小了,但len怎么更長了?
??? delay(500);
??? Serial.write(fb->buf, fb->len);//輸出圖像數(shù)據(jù)
}
}
void loop() {
}

#////////////////////////////////////////////////////////////////////////////////////////////

2、上位機(jī)python代碼:

#////////////////////////////////////////////////////////////////////////////////////////////

#串口圖片通訊
#usr/bin/python3
# -*- coding: utf-8 -*-
import serial #python自帶串行通訊模塊
import matplotlib.pyplot as plt # plt 用于顯示圖片
import numpy as np
import CV2 #opencv
from time import sleep

ser = serial.Serial('com3', 115200, timeout=0.1) #設(shè)置串口名稱,波特率,超時(shí)時(shí)間
?
?
def recv(serial):
??????? while True:
??????????????? data = serial.read(1024)#設(shè)置1024緩沖區(qū)
??????????????? if data == '':
??????????????????????? continue
??????????????? else:
??????????????????????? break
??????????????? sleep(0.02)
??????? return data

img = b'' #字節(jié)連接,定義全局字節(jié)變量以備使用
recev = 0 #接收標(biāo)志位
while True:
??????? data = recv(ser)
#???????? print(len(data))#圖片數(shù)據(jù)按1024分段接收
#???????? print(type(data))#output:<class 'bytes'>
??????? if data:
??????????? try:
??????????????? print(data.decode())
??????????? except:
??????????????? if (b'\xff\xd8' in data) or (recev):#jpg圖片開始字節(jié)為b'\xff\xd8',若存在則開始接受數(shù)據(jù),接下來用標(biāo)志位保持接收
??????????????????? recev = 1 #接收標(biāo)志位置1
??????????????????? img += data #圖片接收后分段連接
??????????????????? print('開始接收圖片:',len(img))#圖片數(shù)據(jù)按1024分段接收
??????????????????? #sleep(0.02)#不加延時(shí)下面的判斷會(huì)出錯(cuò)
??????????????????? if b'\xff\xd9' in data: #jpg圖片開始字節(jié)為b'\xff\xd9,若存在則停止接受數(shù)據(jù)
??????????????????????? print('接收圖片完成:',len(img))#圖片數(shù)據(jù)按1024分段接收
??????????????????????? nparr = np.frombuffer(img, np.uint8)#圖片字節(jié)數(shù)據(jù)轉(zhuǎn)換np.uint8
??????????????????????? img_np = CV2.imdecode(nparr, CV2.IMREAD_COLOR) #利用opencv轉(zhuǎn)換成圖片格式
??????????????????????? print(np.shape(img_np))
??????????????????????? plt.imshow(img_np[:,:,::-1]) # 顯示圖片,opencv的bgr轉(zhuǎn)換用[:,:,::-1]操作即可
??????????????????????? #plt.axis('off') # 不顯示坐標(biāo)軸
??????????????????????? plt.show()
??????????????????????? img = b'' #完成圖片顯示,清空圖片緩沖區(qū)內(nèi)存
??????????????????????? recev = 0 #接收標(biāo)志位置0


#////////////////////////////////////////////////////////////////////////////////////////////

3、使用方法:

燒寫esp32-cam代碼完成后,運(yùn)行上位機(jī)python代碼,按esp32-cam板上的重啟重啟鍵即可看到輸出。



pyserial串口讀取esp32-cam攝像頭的評(píng)論 (共 條)

分享到微博請遵守國家法律
宜章县| 鄂托克旗| 濮阳市| 方城县| 武定县| 贵州省| 襄垣县| 拉孜县| 大宁县| 宁河县| 扶余县| 富阳市| 临高县| 长宁县| 青浦区| 井研县| 南木林县| 苏尼特左旗| 开化县| 江口县| 永康市| 刚察县| 志丹县| 拉萨市| 安塞县| 赤水市| 新巴尔虎左旗| 南丰县| 资阳市| 北海市| 观塘区| 洛扎县| 武汉市| 桐乡市| 罗平县| 新郑市| 汾西县| 杭锦旗| 武胜县| 平和县| 仪征市|