Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 视频捕获文件名_Python_Python 2.7_Python Imaging Library_Video Capture - Fatal编程技术网

Python 视频捕获文件名

Python 视频捕获文件名,python,python-2.7,python-imaging-library,video-capture,Python,Python 2.7,Python Imaging Library,Video Capture,我是新来的,这是我的第一篇帖子。我在视频捕获方面遇到了一个问题:我想让我拍摄的照片的名称在“for”功能中自动更改,并将照片保存在我选择的目录中,但我不知道我要做什么,也没有在互联网上找到它。如果有人知道,请帮帮我。以下是命令行的示例: from VideoCapture import Device cam = Device() cam.saveSnapshot('here i want to call a variable, but i don't know how.jpg') 就是这样。我

我是新来的,这是我的第一篇帖子。我在视频捕获方面遇到了一个问题:我想让我拍摄的照片的名称在“for”功能中自动更改,并将照片保存在我选择的目录中,但我不知道我要做什么,也没有在互联网上找到它。如果有人知道,请帮帮我。以下是命令行的示例:

from VideoCapture import Device
cam = Device()
cam.saveSnapshot('here i want to call a variable, but i don't know how.jpg')
就是这样。我也不知道我必须在哪里写目录


<谢谢>

C++中,通常你会把字符串与<代码> OSTRing流结合在一起,类似这样的事情:

std::ostringstream filename;

for (int i=0; i<10; i++) {
    filename << "variable: " << i << ".jpg";
    cam.saveSnapshot(filename.str().c_str());
}
std::ostringstream文件名;
对于(int i=0;i,
saveSnapshot()
方法的第一个非
self
参数是文件名。
参考:

这意味着你可以做这样的事情:

import os
from VideoCapture import Device

save_dir = '/path/to/my/img/dir' # or for windows: `c:/path/to/my/img/dir` 
img_file_name = 'an_image.jpg'

cam = Device()
cam.saveSnapshot( os.path.join(save_dir, img_file_name) )

好的,这很简单

from VideoCapture import Device
from os.path import join, exists
# We need to import these two functions so that we can determine if
# a file exists.

import time
# From your question I'm implying that you want to execute the snapshot
# every few seconds or minutes so we need the time.sleep function.

cam = Device()

# First since you want to set a variable to hold the directory into which we
# will be saving the snapshots.
snapshotDirectory = "/tmp/" # This assumes your on linux, change it to any 
# directory which exists.

# I'm going to use a while loop because it's easier...
# initialize a counter for image1.jpg, image2.jpg, etc...
counter = 0

# Set an amount of time to sleep!
SLEEP_INTERVAL = 60 * 5 # 5 minutes!

while True:

    snapshotFile = join(snapshotDirectory, "image%i.jpg" % counter)
    # This creates a string with the path "/tmp/image0.jpg"
    if not exists(snapshotFile):
        cam.saveSnapshot(snapshotFile)
        time.sleep(SNAPSHOT_INTERVAL)
    # if the snapshot file does not exist then create a new snapshot and sleep
    # for a few minutes.

    #finally increment the counter.
    counter = counter + 1

就是这样,这应该完全符合您的要求。

我认为
c++
标记添加错误。如果我弄错了,请重新添加。