首页 > 解决方案 > linux 与 python 使用 OpenCV 得到了 QObject moveToThread

问题描述

当我在 Linux 系统中使用 python virtualenv 和 OpenCV 运行这段代码时:

import glob as gb
import cv2
import random
import os
img_path_htc=gb.glob("/home/project/venv/data/train/new/*.jpg")
counter= 1
for path in img_path_htc:
    img = cv2.imread(path)
    cv2.imshow("img",img)
    cv2.waitKey(1000) 
    for i in range(10):
    x = random.randint(300, img.shape[1] - 300 - 256 )
    y = random.randint(300, img.shape[0] - 300 - 256 )
    crop_img = img[y:y+256,x:x+256]
    save_path = "/home/project/venv/data/train/new/patch"
    filename='img'+str(counter)+'.jpg'
    counter=counter+1
    savepath = os.path.join(save_path,filename)
    cv2.imshow("crop_img"+str(i),crop_img)
    cv2.imwrite(savepath, crop_img)
    cv2.waitKey(1000)

我收到了这个错误:

QObject::moveToThread: Current thread (0x128e5e0) is not the object's thread (0x193bf70).
Cannot move to target thread (0x128e5e0)

谢谢。

标签: pythonlinuxopencvvirtualenv

解决方案


推荐阅读