天道酬勤,学无止境

python-imageio

Why is my gif missing png files after 753 iterations

问题 import imageio import os filenames =[] dirPath = "D:\\BandSim_2017-06-20_12_00_45\\" for file in os.listdir(dirPath): if file.endswith(".png"): filenames.append(dirPath+file) moviePath ="D:\\simulation.gif" with imageio.get_writer(moviePath,mode='I', duration=0.1) as writer: i=0 for filename in filenames: image = imageio.imread(filename) writer.append_data(image) print filename

2022-05-17 05:15:06    分类:技术分享    python-2.7   animation   gif   animated-gif   python-imageio

Image processing with single to multiple images

I have an Image showing below: I need to crop the order using python coding. What I need is only the card. So I want to crop the border. How to do it?? This is the output I got using the code mentioned in the below comment.

2022-05-01 23:58:50    分类:问答    python   python-3.x   image-processing   python-imaging-library   python-imageio

Why is my gif missing png files after 753 iterations

I'm using the following python code to generate a .gif file from about 3000 .png files. But the .gif file has only about 1000 .png files. Why is the .gif not having all the .png files? Is there a limit to the number of .png files I can combine to create a .gif file? import imageio import os filenames =[] dirPath = "D:\\BandSim_2017-06-20_12_00_45\\" for file in os.listdir(dirPath): if file.endswith(".png"): filenames.append(dirPath+file) moviePath ="D:\\simulation.gif" with imageio.get_writer(moviePath,mode='I', duration=0.1) as writer: i=0 for filename in filenames: image = imageio.imread

2022-04-28 18:47:58    分类:问答    python-2.7   animation   gif   animated-gif   python-imageio

Video is black when framerate is too low using imageio and Python

I have the following exmaple code: import numpy as np writer = imageio.get_writer('test.mp4', fps=1) max = 800 resolution = 256 for idx in range(1, max): img = np.zeros((resolution,resolution)) img[: int((idx / max) * resolution), : int((idx / max) * resolution)] = 255 img = img.astype(np.uint8) writer.append_data(img) writer.close() The video is just black for fps == 1 What am I missing here? I cannot see any clues in the documentation saying I cannot have fps = 1? EDIT For fps >= 10 it seems to be fine.

2022-04-16 12:22:51    分类:问答    python-3.x   ffmpeg   mp4   python-imageio

"float" object cannot be interpreted as an integer while reading the frame

I am trying to read the frames using imageio API. I have a reader as an object which I have received using imageio.get_reader(video_path,"ffmpeg"). I have the following frame reader function def read_frames(reader, frame_q, use_webcam): if use_webcam: time.sleep(15) frame_cnt = 0 while True: #if frame_cnt % 5 == 0: # ret, frame = reader.read() # cur_img = frame[:,:,::-1] # frame_q.put(cur_img) #else: # ret, frame = reader.read() ret, frame = reader.read() cur_img = frame[:,:,::-1] # bgr to rgb from opencv reader frame_q.put(cur_img) if frame_q.qsize() > 100: time.sleep(1) else: time.sleep

2022-04-16 12:00:56    分类:问答    python   python-imageio

ValueError: 找不到在模式“i”下读取指定文件的格式(ValueError: Could not find a format to read the specified file in mode 'i')

问题 我正在尝试将一个 png 文件读入在 docker 中运行的 python-flask 应用程序中,并且收到一个错误消息 ValueError: 找不到在模式“i”下读取指定文件的格式 我已经使用 HTML 文件上传了一个文件,现在我正在尝试读取它以进行进一步处理。 我看到 scipy.misc.imread 已被弃用,我正在尝试用 imageio.imread 替换它 if request.method=='POST': file = request.files['image'] if not file: return render_template('index.html', label="No file") #img = misc.imread(file) img = imageio.imread(file) 我收到此错误: File "./appimclass.py", line 34, in make_prediction img = imageio.imread(file) File "/usr/local/lib/python3.6/site-packages/imageio/core/functions.py", line 221, in imread reader = read(uri, format, "i", **kwargs) File "/usr

2021-12-03 19:49:21    分类:技术分享    python-3.x   python-imageio

ValueError: Could not find a format to read the specified file in mode 'i'

I am trying to read a png file into a python-flask application running in docker and am getting an error that says ValueError: Could not find a format to read the specified file in mode 'i' i have uploaded a file using an HTML file and now i am trying to read it for further processing. i see that scipy.misc.imread is deprecated and i am trying to replace this with imageio.imread if request.method=='POST': file = request.files['image'] if not file: return render_template('index.html', label="No file") #img = misc.imread(file) img = imageio.imread(file) i get this error : File "./appimclass.py"

2021-11-22 06:22:05    分类:问答    python-3.x   python-imageio

如何从 numpy 数组创建 .fits 文件(How to Create .fits file from numpy array)

问题 我目前正在尝试将 .cr2 转换为 .fits 文件。 我目前无法创建 .fits,因为我创建的任何文件都因拟合形状错误而无法打开或工作。 我曾尝试使用解决方案 Write 3d Numpy array to FITS file with Astropy,但仍然不起作用。 import numpy as np from astropy.io import fits im = imageio.imread(r'E:\FYP\cr.cr2', format="RAW-FI") a = np.array(im) print (a.shape) hdu = fits.PrimaryHDU(a) hdulist = fits.HDUList([hdu]) hdulist.writeto(r'E:\FYPcr.fits') 它成功创建了 .fits 文件,但是在打开“无法读取适合文件”时出现错误。 每当我尝试打开从其他软件创建的 fits 文件时,它都会毫无问题地打开。

2021-10-25 09:21:01    分类:技术分享    python   numpy   astropy   fits   python-imageio

How to Create .fits file from numpy array

I am currently trying to convert a .cr2 into .fits file. I am currently unable to create .fits as any file I create doesn't open or work because of the wrong shape of fits. I have tried using the solution Write 3d Numpy array to FITS file with Astropy but, still, it doesn't work. import numpy as np from astropy.io import fits im = imageio.imread(r'E:\FYP\cr.cr2', format="RAW-FI") a = np.array(im) print (a.shape) hdu = fits.PrimaryHDU(a) hdulist = fits.HDUList([hdu]) hdulist.writeto(r'E:\FYPcr.fits') It successfully creates the .fits file but, gives an error when opened "Cannot read fits file"

2021-10-22 13:59:53    分类:问答    python   numpy   astropy   fits   python-imageio

使用 Python Imageio 在 gif 中制作透明背景(transparent background in gif using Python Imageio)

问题 基本上,我使用以下代码从图像中制作 gif,我的图像是具有透明背景的png ,但 gif 是黑色背景。 我不知道如何制作具有透明背景的 gif。 #gif writer with io.get_writer('my.gif', mode='I', duration=0.1) as writer: for filename in file_names: image = io.imread(filename) writer.append_data(image) #writer.close() 其中filenames是一个包含所有要使用的文件名称的数组。 回答1 尝试箭头 from PIL import Image def gen_frame(path): im = Image.open(path) alpha = im.getchannel('A') # Convert the image into P mode but only use 255 colors in the palette out of 256 im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=255) # Set all pixel values below 128 to 255 , and the rest to 0 mask

2021-10-19 17:06:51    分类:技术分享    python   python-imageio