如何从linux中的文件夹逐个获取jpeg图像输入?

时间:2020-12-17 21:23:45

I have written a image processing program in linux using opencv. Currently I am giving input image as a argument (argv[1]) . I want to take mutiple images one by one from a folder which contains many jpeg images. My plan is to make it like a slide show of processed image.

我使用opencv在linux上编写了一个图像处理程序。目前我将输入图像作为参数(argv [1])。我想从包含许多jpeg图像的文件夹中逐个拍摄多个图像。我的计划是让它像加工图像的幻灯片一样。

1 个解决方案

#1


0  

How about using glob module to get list of every jpg file in directory ?

如何使用glob模块获取目录中每个jpg文件的列表?

import glob
import sys
import cv2
cv2.namedWindow('frame',cv2.WINDOW_NORMAL)
file_list = glob.glob('%s/*.jpg' % sys.argv[1])
for i in file_list:
     frame = cv2.imread(i)                                                  
     cv2.imshow('frame',frame)
     cv2.waitKey(1000) '''time out for 1 sec'''

Where, argv[1] is path of the directory. Once you've a list of files, you can run a loop and run a slideshow like mentioned above.

其中,argv [1]是目录的路径。一旦有了文件列表,就可以运行循环并运行如上所述的幻灯片。

Please note that, this is the quick implementation of your problem in Python. You can very well convert it in c++.

请注意,这是在Python中快速实现您的问题。你可以用c ++很好地转换它。

Hope it helps.

希望能帮助到你。

#1


0  

How about using glob module to get list of every jpg file in directory ?

如何使用glob模块获取目录中每个jpg文件的列表?

import glob
import sys
import cv2
cv2.namedWindow('frame',cv2.WINDOW_NORMAL)
file_list = glob.glob('%s/*.jpg' % sys.argv[1])
for i in file_list:
     frame = cv2.imread(i)                                                  
     cv2.imshow('frame',frame)
     cv2.waitKey(1000) '''time out for 1 sec'''

Where, argv[1] is path of the directory. Once you've a list of files, you can run a loop and run a slideshow like mentioned above.

其中,argv [1]是目录的路径。一旦有了文件列表,就可以运行循环并运行如上所述的幻灯片。

Please note that, this is the quick implementation of your problem in Python. You can very well convert it in c++.

请注意,这是在Python中快速实现您的问题。你可以用c ++很好地转换它。

Hope it helps.

希望能帮助到你。