问题描述
我在 python 中有这个代码:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.Boxlayout import BoxLayout
import time
import pixellib
from pixellib.instance import custom_segmentation
Builder.load_string('''
<CameraClick>:
orientation: 'vertical'
Camera:
id: camera
resolution: (640,480)
play: False
ToggleButton:
text: 'Play'
on_press: camera.play = not camera.play
size_hint_y: None
height: '48dp'
Button:
text: 'Capture'
size_hint_y: None
height: '48dp'
on_press: root.capture()
''')
class CameraClick(BoxLayout):
def capture(self):
'''
Function to capture the images and give them the names
according to their captured time and date.
'''
camera = self.ids['camera']
timestr = time.strftime("%Y%m%d_%H%M%s")
camera.export_to_png("IMG_{}.png".format(timestr))
print("Captured")
segment_image = custom_segmentation()
segment_image.inferConfig(num_classes=1,class_names=["BG","Chicken"])
segment_image.load_model("mask_rcnn_model.006-0.082479.h5")
segment_image.segmentimage("IMG_{}.png".format(timestr),show_bBoxes=True,output_image_name="saidas/out_IMG_{}.png".format(timestr))
class TestCamera(App):
def build(self):
return CameraClick()
TestCamera().run()
在这段代码中,我拍照并处理保存的图片,从而识别鸡肉,但我也想实时进行识别。那么,如何在 kivy 中插入此代码来补充我的代码:
import pixellib
from pixellib.instance import custom_segmentation
import cv2
cam = cv2.VideoCapture(0)
segment_camera = custom_segmentation()
segment_camera.inferConfig(num_classes=1,"Chicken"])
segment_camera.load_model("mask_rcnn_model.005-0.098539.h5")
segment_camera.process_camera(cam,output_video_name="output_video.mp4",show_frames= True,frame_name= "frame",check_fps=True,mask_points_values=True)
我试了几次,都失败了。那么,是否可以插入上面的代码?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)