「Finish Spreading Flowers」では、intel realsense D435i デプスカメラを使用して情報を取得し、DOBOT MG400 マニピュレータで動的なリアルタイムキャプチャを実現し、GUI インターフェイスを作成します (Python で実装)

GUIインターフェイスは以下の通り、ちょっと見苦しいですが、使いやすいですよ、ふふ。​ 

GUI部分

 

1. GUIインターフェースで実現できる機能

  • カメラ画面の一時停止/再開
  • カラーRGB画像、深度画像、オープン演算結果画像、画像処理後の画像を表示(右側)
  • opencv輪郭検索ボックスの選択領域範囲を調整する
  • 画像領域を調整する
  • dobot マニピュレータを有効にする
  • マニピュレータの移動、リセット、ジョースイッチ、Z軸上下移動、自動運転・停止

2.GUI部品コード

①レイアウト

1. メニューバー f1

"""
菜单栏 f1
"""
f1 = Frame(root)
info_width = 1280
info_height = 30
canvas_menu = Canvas(f1, width=info_width, height=info_height)
canvas_menu.pack(side=LEFT, padx=1, pady=1)
f1.pack()

メニューバーには現在何もなく、機能もありませんが、バックアップがあります

2. 機能エリア f2

"""
功能区域 f2
"""
f2 = Frame(root)
# info_width = 1280
# info_height = 434
frame_fun = Frame(f2, width=880, height=324)
frame_screenshot = Frame(f2, width=400, height=324)
frame_fun.pack(side=LEFT, padx=1, pady=1)
frame_screenshot.pack(side=LEFT, padx=1, pady=1)
f2.pack()

ボタン

btn_pause = Button(frame_fun, text="CAMERA PAUSE", width=10, height=1, command=pause_camera)
btn_pause.place(x=10, y=10)
btn_dobot_pause = Button(frame_fun, text="ロボット起動", width=10, height=1, command=dobot_enable)
btn_dobot_pause.place(x=110, y=10)
btn_dobot_move = Button(frame_fun, text="目標位置へ移動", width=10, height=1, command=dobot_move)
btn_dobot_move.place(x=210, y=10)
btn_dobot_move_home = Button(frame_fun, text="原点", width=10, height=1, command=dobot_move_home)
btn_dobot_move_home.place(x=310, y=10)
btn_dobot_nail_on = Button(frame_fun, text="チャック開", width=10, height=1, command=dobot_nail_on)
btn_dobot_nail_on.place(x=410, y=10)
btn_dobot_nail_off = Button(frame_fun, text="チャック閉", width=10, height=1, command=dobot_nail_off)
btn_dobot_nail_off.place(x=510, y=10)
btn_dobot_move_down = Button(frame_fun, text="down", width=10, height=1, command=dobot_move_down)
btn_dobot_move_down.place(x=610, y=10)
btn_dobot_move_up = Button(frame_fun, text="up", width=10, height=1, command=dobot_move_up)
btn_dobot_move_up.place(x=710, y=10)
btn_dobot_automove = Button(frame_fun, text="自動運転", width=10, height=1, command=dobot_automove)
btn_dobot_automove.place(x=610, y=60)
btn_dobot_automove_stop = Button(frame_fun, text="自動運転停止", width=10, height=1, command=dobot_automove_stop)
btn_dobot_automove_stop.place(x=710, y=60)

エリアスライダーを確認してください

# 检出面积滑块们
var_min = IntVar()
scl_area_min = Scale(frame_fun, orient=HORIZONTAL, length=200, width=10, from_=1000, to=5000, label='最小検出サイズ (1500)', tickinterval=1, resolution=50, variable=var_min)
area_min = 1500
var_min.set(1500)
scl_area_min.bind('<ButtonRelease-1>', get_var_min)
scl_area_min.place(x=10, y=60)

var_max = IntVar()
scl_area_max = Scale(frame_fun, orient=HORIZONTAL, length=200, width=10, from_=1000, to=5000, label='最大検出サイズ (5000)', tickinterval=1, resolution=50, variable=var_max)
area_max = 5000
var_max.set(5000)
scl_area_max.bind('<ButtonRelease-1>', get_var_max)
scl_area_max.place(x=230, y=60)

トリミング領域スライダー

# 裁剪面积滑块们
var_sliced_left = IntVar()
scl_sliced_left = Scale(frame_fun, orient=HORIZONTAL, length=200, width=10, from_=0, to=640, label='sliced_left (500)', tickinterval=1, resolution=10, variable=var_sliced_left)
sliced_left = 540
var_sliced_left.set(540)
scl_sliced_left.bind('<ButtonRelease-1>', get_sliced_left)
scl_sliced_left.place(x=10, y=140)

var_sliced_right = IntVar()
scl_sliced_right = Scale(frame_fun, orient=HORIZONTAL, length=200, width=10, from_=640, to=1280, label='sliced_right (930)', tickinterval=1, resolution=10, variable=var_sliced_right)
sliced_right = 960
var_sliced_right.set(960)
scl_sliced_right.bind('<ButtonRelease-1>', get_sliced_right)
scl_sliced_right.place(x=230, y=140)

var_sliced_up = IntVar()
scl_sliced_up = Scale(frame_fun, orient=HORIZONTAL, length=200, width=10, from_=0, to=360, label='sliced_up (150)', tickinterval=1, resolution=10, variable=var_sliced_up)
sliced_up = 220
var_sliced_up.set(220)
scl_sliced_up.bind('<ButtonRelease-1>', get_sliced_up)
scl_sliced_up.place(x=450, y=140)

var_sliced_down = IntVar()
scl_sliced_down = Scale(frame_fun, orient=HORIZONTAL, length=200, width=10, from_=360, to=720, label='sliced_down (570)', tickinterval=1, resolution=10, variable=var_sliced_down)
sliced_down = 570
var_sliced_down.set(570)
scl_sliced_down.bind('<ButtonRelease-1>', get_sliced_down)
scl_sliced_down.place(x=670, y=140)

ログログ部分

# log日志
message_dobot = Text(frame_fun, height=1, cursor='arrow', width=25)
message_dobot.insert("insert", "wait for dobot")
message_dobot.config(fg='red')
message_dobot.place(x=10, y=280)
message_log = Text(frame_fun, height=1, cursor='arrow', width=25)
message_log.place(x=10, y=300)

3. カメラ画面下部

"""
相机区域 f3
"""
f3 = Frame(root)
frame_width = 427
frame_height = 366
rgb_frame = Frame(f3, width=frame_width, height=frame_height)
depth_frame = Frame(f3, width=frame_width, height=frame_height)
opening_frame = Frame(f3, width=frame_width, height=frame_height)
rgb_frame.pack(side=LEFT, padx=1, pady=1)
depth_frame.pack(side=LEFT, padx=1, pady=1)
opening_frame.pack(side=LEFT, padx=1, pady=1)
f3.pack()

rgb_info = Label(rgb_frame, text="LIVE", font=("游明朝", 10))
rgb_info.place(x=5, y=0)
canvas_rgb = Canvas(rgb_frame)
canvas_rgb.place(x=25, y=50)
depth_info = Label(depth_frame, text="DEPTH", font=("游明朝", 10))
depth_info.place(x=5, y=0)
canvas_depth = Canvas(depth_frame)
canvas_depth.place(x=25, y=50)
opening_info = Label(opening_frame, text="OPENING", font=("游明朝", 10))
opening_info.place(x=5, y=0)
canvas_opening = Canvas(opening_frame)
canvas_opening.place(x=25, y=50)

②ボタンに紐付けられた機能

  • 画面を一時停止/再開します def stop_camera():

 この部分は比較的単純で、realsense カメラ クラスを宣言し、クラス内の一時停止状態を変更するだけです。

class State:
    def __init__(self, *args, **kwargs):
        self.WIN_NAME = 'RealSense'
        self.paused = False

state = State()
def pause_camera():
    state.paused ^= True
  • スライダー値を取得します。例として、左のトリミング領域の値を取得することを考えます。 def get_sliced_left(event):
def get_sliced_left(event):
    global sliced_left
    sliced_left = int(var_sliced_left.get())
  •  ロボット有効化定義 dobot_enable():

tcp-ip アドレスを使用してロボットに接続し、マルチスレッド オブジェクトを作成します。ロボット アームは情報を受信するとすぐに戻るため、ループの最後で Sync() コマンドを 30003 に送信してブロックする必要があります。 、前の実行が完了するのを待ってから 0Sync( ) をフィードバックします。そうしないと、プログラムが停止し、ロボット アームがまだ実行されている状況が発生します。{}​ 

def dobot_enable():
    global lj29999
    global lj30003
    lj29999 = LJ29999("192.168.1.6", 29999)  # 创建实例对象
    lj30003 = LJ30003("192.168.1.6", 30003)
    # # 根据自己处理器自行判断使用线程还是进程
    thread = Thread(target=FK,  # 新建一个线程做数据刷新
                    daemon=True  # 设置新线程为daemon线程
                    )
    thread.start()
    lj29999.send(" EnableRobot()")
    print("机器人使能中...")
    message_dobot.delete(1.0, END)
    message_dobot.insert("insert", "机器人使能中...")
    message_dobot.config(fg='black')
def FK():
    fk30005 = feedback("192.168.1.6", 30005)  # 处理器性能较弱可以使用30005反馈
    while True:
        time.sleep(0.021)  # 略大于反馈时间即可
        fk30005.read()
        # print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        # print((fk30005.basics[1]))  # 打印轴实时位置

③下のビデオエリア

message_log.delete(1.0, END)
message_log.insert("insert", "live中...")
image_to_arm, arm_to_image = coordinate_transform()
img_color, img_depth, color_intrin, intr_matrix, color_intrin_coeffs, aligned_depth_frame, depth_mapped_image = get_aligned_images()
target_rgb, target_depth, target_opening = camera()
canvas_rgb.create_image(0, 0, anchor='nw', image=target_rgb)
canvas_depth.create_image(0, 0, anchor='nw', image=target_depth)
canvas_opening.create_image(0, 0, anchor='nw', image=target_opening)

root.update()
root.after(1)

ビデオの実装中、カメラの各画像を取得した後、画像がキャンバス上に作成され、ビデオ効果を実現するためにリアルタイムで更新されます。

完成したプログラムファイルは後日アップします~!

おすすめ

転載: blog.csdn.net/weixin_49828565/article/details/127507680