首页 \ 问答 \ OpenCV - 将图像保存到选定的特定文件夹(OpenCV - Saving images to a particular folder of choice)

OpenCV - 将图像保存到选定的特定文件夹(OpenCV - Saving images to a particular folder of choice)

我正在学习OpenCV和Python。 我从网络摄像头捕捉了一些图像并保存了它们。 但是它们被默认保存到本地文件夹中。 我想从直接路径将它们保存到另一个文件夹。 我如何解决它?


I'm learning OpenCV and Python. I captured some images from my webcam and saved them. But they are being saved by default into the local folder. I want to save them to another folder from direct path. How do I fix it?


原文:https://stackoverflow.com/questions/41586429
更新时间:2022-10-15 14:10

最满意答案

我无法说出你正在做的计算,但似乎你只是想安排组合。 问题是它们是否是有向或无向的 - 也就是说,是否需要计算流量(A,B)和流量(B,A),还是只计算一个流量?

如果只有一个,你可以这样做:

for i,ward_list in enumerate(idgroups):
    for j,ward_list2 in enumerate(idgroups[i:],start=i):

这将迭代i,j对,如下所示:

0,0 0,1 0,2 ... 0,n
1,1 1,2 ... 1,n
2,2 ... 2,n

这将在无向情况下发挥作用。

如果你需要计算流(A,B)和流(B,A),那么你可以简单地将你的代码放到一个称为flows的函数中,并用反向参数调用它,如图所示。 ;-)

更新

我们来定义一个名为flows的函数:

def flows():
    pass

现在,什么是参数?

好吧,看着你的代码,它从DataFrame获取数据。 你需要两个不同的病房,所以我们从这些开始。 结果似乎是结果网格的总和。

def flows(df, ward_a, ward_b):
    """Return the sum of all the cells in the row/column intersections
    of ward_a and ward_b."""

    return 0

现在我要复制你的代码行:

    ward_list = idgroups[index]
    print ward_list
    df6 = mergedcsv.loc[ward_list] #select rows with values in the list
    dfcols = mergedcsv.loc[ward_list, :] #select columns with values in list
    ward_liststr = map(str, ward_list) #convert ward_list to strings so that they can be used to select columns, won't work as integers.
    ward_listint = map(int, ward_list)
    #dfrowscols = mergedcsv.loc[ward_list, ward_listint]
    df7 = df6.loc[:, ward_liststr]
    print df7
    regflowsum = df7.values.sum() #sum all values in dataframe
    intflow = [regflowsum]
    print intflow

我认为这是大部分flow功能。 我们看看吧。

  1. ward_list显然是ward_award_b参数。

  2. 我不确定df6是什么,因为你在df7中重新计算它。 所以需要澄清。

  3. regflowsum是我们期望的输出,我想。

重写这个函数:

def flows(df, ward_a, ward_b):
    """Return the sum of all the cells in the row/column intersections
    of ward_a and ward_b."""

    print "Computing flows from:"
    print "    ", ward_a
    print ""
    print "flows into:"
    print "    ", ward_b

    # Filter rows by ward_a, cols by ward_b:
    grid = df.loc[ward_a, ward_b]

    print "Grid:"
    print grid

    flowsum = grid.values.sum()

    print "Flows:", flowsum

    return flowsum

现在,我认为ward_award_b值已经是正确的格式。 所以我们必须强化它们或者其他功能之外的任何东西。 让我们这样做:

for ax, group_a in enumerate(idgroups):
    ward_a = map(str, group_a)

    for bx, group_b in enumerate(idgroups[ax:], start=ax):
        ward_b = map(str, group_b)

        flow_ab = flows(mergedcsv, ward_a, ward_b)

        if ax != bx:
            flow_ba = flows(mergedcsv, ward_b, ward_a)
        else:
            flow_ba = flow_ab

        # Now what?

此时,你有两个数字。 当病房相同时(内部流量?),它们将是平等的。 在这一点上,你原来的代码不再有用,因为它只处理内部流,而不是A-> B流,所以我不知道该怎么做。 但值是在变量中,所以...


I can't speak to the computations you're doing, but it seems like you just want to arrange combinations of groups. The question is whether they are directed or undirected- that is, do you need to compute flows(A,B) and flows(B,A), or just one?

If just one, you could do this:

for i,ward_list in enumerate(idgroups):
    for j,ward_list2 in enumerate(idgroups[i:],start=i):

This would iterate over i,j pairs like:

0,0 0,1 0,2 ... 0,n
1,1 1,2 ... 1,n
2,2 ... 2,n

which would serve in the undirected case.

If you need to compute both flows(A,B) and flows(B,A), then you can simply push your code into a function called flows, and call it with reversed args, as shown. ;-)

Update

Let's define a function called flows:

def flows():
    pass

Now, what are the parameters?

Well, looking at your code, it gets data from a DataFrame. And you want two different wards, so let's start with those. The result seems to be a sum of the resulting grid.

def flows(df, ward_a, ward_b):
    """Return the sum of all the cells in the row/column intersections
    of ward_a and ward_b."""

    return 0

Now I'm going to copy lines of your code:

    ward_list = idgroups[index]
    print ward_list
    df6 = mergedcsv.loc[ward_list] #select rows with values in the list
    dfcols = mergedcsv.loc[ward_list, :] #select columns with values in list
    ward_liststr = map(str, ward_list) #convert ward_list to strings so that they can be used to select columns, won't work as integers.
    ward_listint = map(int, ward_list)
    #dfrowscols = mergedcsv.loc[ward_list, ward_listint]
    df7 = df6.loc[:, ward_liststr]
    print df7
    regflowsum = df7.values.sum() #sum all values in dataframe
    intflow = [regflowsum]
    print intflow

I think this is most of the flow function right here. Let's look.

  1. The ward_list will obviously be either the ward_a or ward_b parameters.

  2. I'm not sure what df6 is, because you sort of recompute it in df7. So that need to be clarified.

  3. regflowsum is our desired output, I think.

Rewriting this into the function:

def flows(df, ward_a, ward_b):
    """Return the sum of all the cells in the row/column intersections
    of ward_a and ward_b."""

    print "Computing flows from:"
    print "    ", ward_a
    print ""
    print "flows into:"
    print "    ", ward_b

    # Filter rows by ward_a, cols by ward_b:
    grid = df.loc[ward_a, ward_b]

    print "Grid:"
    print grid

    flowsum = grid.values.sum()

    print "Flows:", flowsum

    return flowsum

Now, I have assumed that the ward_a and ward_b values are already in the correct format. So we'll have to str-ify them or whatever outside the function. Let's do that:

for ax, group_a in enumerate(idgroups):
    ward_a = map(str, group_a)

    for bx, group_b in enumerate(idgroups[ax:], start=ax):
        ward_b = map(str, group_b)

        flow_ab = flows(mergedcsv, ward_a, ward_b)

        if ax != bx:
            flow_ba = flows(mergedcsv, ward_b, ward_a)
        else:
            flow_ba = flow_ab

        # Now what?

At this point, you have two numbers. They will be equal when the wards are the same (internal flow?). At this point your original code stops being helpful because it only deals with internal flows, and not A->B flows, so I don't know what to do. But the values are in the variables, so ...

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)