同時控制步進電機和相機的最佳方法是什么?假設相機放置在線性平臺(步進電機)上,我想以 1 mm 的步長移動平臺并在每一步結束時捕獲一幀。兩個設備(相機和舞臺)都通過 2 個不同的 USB 2.0 端口連接到我的電腦(Ubuntu 18.04.3 LTS)。我的相機腳本如下所示:def camera(): ... ... ... while(True): cv2.imshow('live', frame) ueye.is_ExitCamera(hCam2) cv2.destroyAllWindows()if __name__ == "__main__": camera()并從攝像機輸出直播。對于電機,例如:i = 0while i < 6: # Move 6 times stepper.Move(0.5) # Moves forward by 0.5 mm time.sleep(1) # Sleeps for a second i += 1time.sleep(2)print("\nProcess End\n")close() # closes port 并根據需要移動和睡覺。單獨執行時,兩個腳本都能成功運行。但是,如何組合這些腳本,以便在每個步驟結束時拍照?對于上面提到的移動 6 次的示例,我想在最后獲得 6 張圖像,在每一步結束時捕獲。是否應該使用多線程、多處理?... 這兩種設備都通過 2 個單獨的 USB 2.0 端口連接到我的計算機。我不是編程的初學者,但也不是專家,所以任何建議都將不勝感激。
1 回答

holdtom
TA貢獻1805條經驗 獲得超10個贊
您不能調用某些在每一步中捕獲圖像的函數是有原因的嗎?
# import modules for camera and stepper control
def step_and_capture(steps=6):
images = []
for x in range(steps):
stepper.Move(0.5)
image = cam_capture_method() # returns a photo or it could write to somewhere
time.sleep(1)
# save the images to folder?
if __name__ == "__main__":
step_and_capture()
添加回答
舉報
0/150
提交
取消