问题描述
我有一个 Python 程序,可以处理用 Cognex 相机拍摄的图像,并为我提供结果 (OK / NOK) 图像, 我想要的例如:如果程序向我们显示图像正常,则绿色 LED 应亮起,如果图像不正常,则红色 LED 应亮起,(两个 LED 连接到 CIO micro Cognex 的输出)
best_model = models.load_model("cnn_casting_inspection.hdf5")
def names(number):
if number == 1:
return 'OK'
else:
return 'NOK'
# cognex's config
ip = "169.254.2.202"
user = 'admin'
password = ''
#out = cv2.VideoWriter('output.mp4',-1,20.0,(300,300))
while True:
start_time = time.time()
tn = telnetlib.Telnet(ip)
telnet_user = user+'\r\n'
tn.write(telnet_user.encode('ascii'))
tn.write("\r\n".encode('ascii'))
tn.write(b"SE8\r\n")
ftp = FTP(ip)
ftp.login(user)
filename = 'image.bmp'
rename = 'image_get.bmp'
lf = open(rename,"wb")
ftp.retrbinary("RETR " + filename,lf.write)
lf.close()
image2 = cv2.imread(rename)
cv2.imshow('Image',image2)
print("--- %s seconds ---" % (time.time() - start_time))
dir_path = "C:/Users/Dell/PycharmProjects/hsd/image_get.bmp"
img = image.load_img(dir_path,target_size=(200,200))
x = np.array(img.resize((300,300)))
x = x.reshape(-1,300,1)
res = best_model.predict_on_batch(x)
classification = np.where(res == np.amax(res))[1][0]
print(str(res[0][classification] * 100) + '% This Is ' + names(classification))
plt.title(names(classification),weight='bold',size=15)
plt.imshow(img)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)