python - 同时控制步进电机和相机

标签 python opencv ubuntu camera pyusb

同时控制步进电机和相机的最佳方法是什么?

假设相机放在线性平台(步进电机)上,我想以 1 毫米的步长移动平台,并在每一步结束时捕捉一帧。两个设备(相机和舞台)都通过 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 = 0
while i < 6:           # Move 6 times
    stepper.Move(0.5)  # Moves forward by 0.5 mm
    time.sleep(1)      # Sleeps for a second
    i += 1

time.sleep(2)
print("\nProcess End\n")
close()                # closes port 

并根据需要移动和 sleep 。

两个脚本单独执行时都运行成功。但是,如何组合这些脚本,以便在每个步骤结束时拍照?对于上面提到的移动 6 次的示例,我想在最后获得 6 张图像,在每一步结束时捕获。应该使用多线程、多处理吗?...这两种设备都通过 2 个独立的 USB 2.0 端口连接到我的计算机。我不是编程初学者,但也不是专家,所以任何建议都将不胜感激。

最佳答案

您不能调用某些在每一步都捕获图像的函数是有原因的吗?

# 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()

关于python - 同时控制步进电机和相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58119737/

相关文章:

python - Ruby 和 Minecraft 数据包

python - python 中更快的方法

Python 视频处理

php - Laravel 中间件抛出 "No supported encrypter found"消息

python - pylab : Bounding box despite frameon=False

python - 如何在 python 3 的版本之间进行更改

c++ - OpenCV findHomography 断言失败错误

opencv - 使用 openCV 检测图像中的白色像素簇

linux - 我的 Bash 脚本运行不正常

linux - ubuntu bash脚本备份/home/$user但保留最新的