简体   繁体   English

Python/OpenCV:使用定义的路径和名称保存图片

[英]Python/OpenCV: Save pictures with defined path and name

would like to save an image in a defined path and with a defined name.想要将图像保存在定义的路径中并具有定义的名称。 The path is fixed, but the name from a variable.路径是固定的,但名称来自变量。 With the name alone is no problem as you see above but how can i input the fixed path?正如您在上面看到的,仅使用名称是没有问题的,但是我如何输入固定路径?

import cv2

img_name = "TEST"

cam = cv2.VideoCapture(0)


cam.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while(True):

    ret, frame = cam.read()
    cv2.imshow('preview',frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        img_name = "{}.jpg".format(img_name)
        cv2.imwrite(img_name, frame)
        break

cam.release()
cv2.destroyAllWindows()

Thanks and best regards :)谢谢和最好的问候:)

import os
import cv2

img_name = "TEST"

cam = cv2.VideoCapture(0)


cam.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while(True):

    ret, frame = cam.read()
    cv2.imshow('preview',frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        img_name = os.path.join("your_path_here", "{}.jpg".format(img_name))
        cv2.imwrite(img_name, frame)
        break

cam.release()
cv2.destroyAllWindows()

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

相关问题 路径名太长,在 Python 中尝试使用 OpenCV 或 PIL.Image 保存图像时出错 - Path name too long, error when trying to save image with OpenCV or PIL.Image in Python opencv和python错误“未定义名称'kernel'” - opencv and python error “ name 'kernel' is not defined” 名称“eyes_roi”未定义,OpenCV 和 Python - name 'eyes_roi' is not defined, OpenCV and Python 将 OpenCV 映像保存到 Python 中的外部服务器路径中 - Save OpenCV image into external server path in Python python2.7名称'__path__'未定义 - python2.7 name '__path__' is not defined 定义一个 Function 以从 label 获取图像,并从条目中获取文件名并保存为 PNG,并在 python ZE5BA8B4CEF509C298AAA15Z22 中定义文件路径 - Define a Function to get image from label and file name from entry and save as PNG with defined file path in python tkinter Python导入错误Opencv NameError:未定义名称highgui - Python Import error Opencv NameError: name highgui is not defined 找到这些图片的中心,OpenCV-Python - Finding the center of these pictures, OpenCV-Python 在python opencv模块中编辑后保存一张同名图片 - Save an image with the same name after editing in python opencv module 按原始名称保存调整大小的图片列表 - Save a list of resized pictures by their original name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM