这个nn模块如何进行添加
K
k1h5
@k1h5
0
声望
8
楼层
376
资料浏览
0
粉丝
0
关注
k1h5 发布的帖子
-
我需要将二值图与彩图进行点乘运算
在openmv中如何同时调用彩图和灰度图,opencv中的Mat dst=img.clone()如何在openmv中表示,我需要将二值图与彩图进行点乘运算,如何用程序来表示。我试着用遍历像素的方法弄了,但是有错误
-
SyntaxError: can't assign to expression出错误报出如何解决,求大神帮忙
import sensor, image, time, math sensor.reset() # Reset and initialize the sensor. sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) sensor.set_framesize(sensor.VGA) # Set frame size to QVGA (320x240) sensor.skip_frames(time = 2000) # Wait for settings take effect. clock = time.clock() # Create a clock object to track the FPS. while(True): #img = sensor.snapshot() # Take a picture and return the image. img = sensor.snapshot() #红色阈值 for y in range(0,480,3): for x in range(0,640): #img.get_pixel(x,y) if img.get_pixel(x,y)>=205: img.get_pixel(x,y)=255 elif img.get_pixel(x,y)<=195: img.get_pixel(x,y)=0 else: img.get_pixel(x,y)=img.get_pixel(x,y)
-
程序不能运行是缺少什么吗?
import numpy as np
x = np.random.randn(20)
y = np.random.randn(20)
k = 3
#1.选取聚类中心
center0=np.array([x[0],y[0]])
center1=np.array([x[1],y[1]])#2.开始迭代
iter = 100
while iter > 0:
print('111111')
res = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(20):
# 2.1计算每个对象与聚类中心的距离
dis0 = np.sqrt((x[i] - center0[0]) ** 2 + (y[i] - center0[1]) ** 2)
dis1 = np.sqrt((x[i] - center1[0]) ** 2 + (y[i] - center1[1]) ** 2)#2.1归类 if(dis0 > dis1): res[i]=1 else: res[i]=0 #2.3新的聚类中心 res0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] res01 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] res1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] res11 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] n0 = 0 n1 = 0 for i in range(20): if res[i] == 0: res0[n0] = x[i] res01[n0] = y[i] n0 += 1 else: res1[n1] = x[i] res11[n1] = y[i] n1 += 1 center0_new = np.array([np.array(res0).mean(), np.array(res01).mean()]) center1_new = np.array([np.array(res1).mean(), np.array(res11).mean()]) #3.判定聚类中心位置是否发生变换 if all((center0 == center0_new) & (center1 == center1_new)): # 如果没发生变换则退出循环,表示已得到最终的聚类中心 break center1=center1_new center0=center0_new
#4.输出结果
for i in range(20):
if res[i] == 0:
print(x[i],y[i],'0')
else:
print(x[i],y[i],'1') -
串口通信与STM32单片机之间的通信
import sensor, image, time import json from pyb import UART sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.skip_frames(10) sensor.set_auto_gain(False) # must be turned off for color tracking sensor.set_auto_whitebal(False) # must be turned off for color tracking clock = time.clock() #串口初始化 uart = UART(3,115200) #初始化串口3,波特率115200 uart.init(115200,bits=8,parity=None,stop=1) #8位数据位 无校验位 1位停止 def sending_data(cx,cy): data = ustruct.pack("<bbhhb", 0x2C, 0x12, int(cx), int(cy), 0x3C) uart.write(data); while(True): sending_data(5,4) time.sleep_ms(1000) print(55555)
name 'ustruct' isn't defined如何解决