繁体   English   中英

在创建的目录中拍照 OpenCV-Python

[英]Take Pictures In Created Directories OpenCV-Python

我正在尝试将图片拍摄到特定目录,然后在我的函数中使用这些图片的路径。 但是,当我尝试为每个单独的“记录实例”创建文件夹时出现错误

我的 Python 代码:

def identify(path):
    cmd = f"darknet.exe detector test cfg/obj.data cfg/yolov4_test.cfg custom-yolov4-detector_best.weights -ext_output -dont_show -out result.json {path}"

    
    os.chdir(r'C:\\Yolo_v4\\darknet\\build\\darknet\\x64')    
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    out = p.stdout.read()
    print(out)
# FIND LAST RECORDED FILE
list_of_files = glob.glob('C:\\Yolo_v4\\darknet\\build\\darknet\\x64\\Captures\\*')
latest_file = max(list_of_files, key=os.path.getctime)


# IMAGE CAPTURE FUNCTION
def imgcap():
    cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
    framerate = cap.get(10)
    x=1


    while(True):
        # Capture frame-by-frame
        ret, frame = cap.read()
        if ret:
            # Our operations on the frame come here
            cv2.imshow("frame", frame)
            dirname = str(os.mkdir('Captures\\CapEvent' + str(int(y))))
            yx=yx+1
            filename = '' + dirname + '\\capture' + str(int(x)) + ".png"
            x=x+1
            cv2.imwrite(filename, frame)
            time.sleep(20)
            identify(latest_file.replace('\\', '\\\\'))
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        else:
            print("Ret False")

    # When everything done, release the capture
    cap.release()
    cv2.destroyAllWindows()

imgcap()

我得到的错误:

  File "vision.py", line 85, in <module>
    latest_file = max(list_of_files, key=os.path.getctime)
ValueError: max() arg is an empty sequence

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM