1. <legend id='msLA0'><style id='msLA0'><dir id='msLA0'><q id='msLA0'></q></dir></style></legend>

    <small id='msLA0'></small><noframes id='msLA0'>

    1. <tfoot id='msLA0'></tfoot>
      <i id='msLA0'><tr id='msLA0'><dt id='msLA0'><q id='msLA0'><span id='msLA0'><b id='msLA0'><form id='msLA0'><ins id='msLA0'></ins><ul id='msLA0'></ul><sub id='msLA0'></sub></form><legend id='msLA0'></legend><bdo id='msLA0'><pre id='msLA0'><center id='msLA0'></center></pre></bdo></b><th id='msLA0'></th></span></q></dt></tr></i><div id='msLA0'><tfoot id='msLA0'></tfoot><dl id='msLA0'><fieldset id='msLA0'></fieldset></dl></div>

      • <bdo id='msLA0'></bdo><ul id='msLA0'></ul>

    2. 遍历图像目录并将它们全部旋转 x 度并保存到目录

      时间:2023-07-03

    3. <tfoot id='IzEtl'></tfoot>
        <bdo id='IzEtl'></bdo><ul id='IzEtl'></ul>

                <tbody id='IzEtl'></tbody>
            • <legend id='IzEtl'><style id='IzEtl'><dir id='IzEtl'><q id='IzEtl'></q></dir></style></legend>
              <i id='IzEtl'><tr id='IzEtl'><dt id='IzEtl'><q id='IzEtl'><span id='IzEtl'><b id='IzEtl'><form id='IzEtl'><ins id='IzEtl'></ins><ul id='IzEtl'></ul><sub id='IzEtl'></sub></form><legend id='IzEtl'></legend><bdo id='IzEtl'><pre id='IzEtl'><center id='IzEtl'></center></pre></bdo></b><th id='IzEtl'></th></span></q></dt></tr></i><div id='IzEtl'><tfoot id='IzEtl'></tfoot><dl id='IzEtl'><fieldset id='IzEtl'></fieldset></dl></div>

              <small id='IzEtl'></small><noframes id='IzEtl'>

              1. 本文介绍了遍历图像目录并将它们全部旋转 x 度并保存到目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 Python、Open、Numpy 和 Scipy.我有一个要旋转特定角度的图像目录.我想编写这个脚本.我正在使用这个,OpenCV Python 旋转围绕特定点 X 度的图像,但它似乎并不像我想象的那样流水线.我得到了一个无效的轮换计划,但我认为我不应该得到这个.

                I am using Python,Open, Numpy, and Scipy. I have a directory of images that I want to rotate by certain angles. I want to script this. I am using this, OpenCV Python rotate image by X degrees around specific point but it doesn't seem to pipeline exactly as I envisioned. I get an invalid rotation plan specified, but I don't think that I should be getting this.

                我的代码如下所示:

                from scipy import ndimage
                import numpy as np
                import os
                import cv2
                
                def main():
                    outPath = "C:Minicondaenvs.."
                    path = "C:Minicondaenvsout.."
                    for image_to_rotate in os.listdir(path):
                        rotated = ndimage.rotate(image_to_rotate, 45)
                        fullpath = os.path.join(outPath, rotated)
                
                  if __name__ == '__main__':
                     main()
                

                推荐答案

                你需要在旋转之前实际读取图像文件.您当前的代码所做的只是遍历文件(和目录)的名称.

                You need to actually read the image file before rotating them. What your current code is doing is just iterating through the names of the files (and directories).

                os.listdir(path) 为您提供文件夹的内容列表(基本上只是名称),然后您需要使用 ndimage.imread()<打开这些文件/em> 函数.

                os.listdir(path) gives you a list of contents of the folder (basically just the name) and then you need to open these files using the ndimage.imread() function.

                这应该可行:

                from scipy import ndimage, misc
                import numpy as np
                import os
                import cv2
                
                def main():
                    outPath = "C:Minicondaenvs.."
                    path = "C:Minicondaenvsout.."
                
                    # iterate through the names of contents of the folder
                    for image_path in os.listdir(path):
                
                        # create the full input path and read the file
                        input_path = os.path.join(path, image_path)
                        image_to_rotate = ndimage.imread(input_path)
                
                        # rotate the image
                        rotated = ndimage.rotate(image_to_rotate, 45)
                
                        # create full output path, 'example.jpg' 
                        # becomes 'rotate_example.jpg', save the file to disk
                        fullpath = os.path.join(outPath, 'rotated_'+image_path)
                        misc.imsave(fullpath, rotated)
                
                if __name__ == '__main__':
                    main()
                

                PS:这种遍历文件夹内容的方式只有在目录中只有文件而没有子目录的情况下才有效.os.listdir(path) 将返回任何文件以及子目录的名称.

                PS: This way of iterating through the contents of the folder only works if there are only files in the directory and no sub-directories. os.listdir(path) will return the names of any files as well as sub-directories.

                您可以从这篇文章中了解如何仅列出目录中的文件:如何列出一个目录下的所有文件?

                You can learn how to list only files in a directory from this post: How to list all files of a directory?

                这篇关于遍历图像目录并将它们全部旋转 x 度并保存到目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                <i id='yzpSq'><tr id='yzpSq'><dt id='yzpSq'><q id='yzpSq'><span id='yzpSq'><b id='yzpSq'><form id='yzpSq'><ins id='yzpSq'></ins><ul id='yzpSq'></ul><sub id='yzpSq'></sub></form><legend id='yzpSq'></legend><bdo id='yzpSq'><pre id='yzpSq'><center id='yzpSq'></center></pre></bdo></b><th id='yzpSq'></th></span></q></dt></tr></i><div id='yzpSq'><tfoot id='yzpSq'></tfoot><dl id='yzpSq'><fieldset id='yzpSq'></fieldset></dl></div>
                  <bdo id='yzpSq'></bdo><ul id='yzpSq'></ul>

                  1. <tfoot id='yzpSq'></tfoot>
                        <tbody id='yzpSq'></tbody>
                      <legend id='yzpSq'><style id='yzpSq'><dir id='yzpSq'><q id='yzpSq'></q></dir></style></legend>

                      1. <small id='yzpSq'></small><noframes id='yzpSq'>