简体   繁体   English

覆盆子pi图像裁剪非常慢

[英]raspberry pi image cropping very slow

I am currently working on a project to capture and process photos on a raspberry Pi. 我目前正在从事一个在树莓派上捕获和处理照片的项目。 The photos are 6000X4000 about 2 mb, from a nikon D5200 camera. 照片是从Nikon D5200相机中取出的6000X4000约2 mb。 Everything is working fine, i have made a proof of concept in Java and want to transform this to python or C depending on which language is faster on the raspberry. 一切工作正常,我已经用Java进行了概念验证,并希望根据树莓上使用哪种语言更快将其转换为python或C。

No the problem is that the images need to be cropped and re-sized, this takes a very long time in the raspberry. 没问题的是图像需要裁剪并重新调整大小,这在树莓中花费了很长时间。 In java the whole process of reading the image, cropping and writing the new image takes about 2 minutes. 在Java中,读取图像,裁剪和写入新图像的整个过程大约需要2分钟。

I have also tried ImageMagick but in command-line this even takes up to 3 minutes. 我也尝试过ImageMagick,但是在命令行中,这甚至需要花费3分钟。

With a small python script i made this is reduces to 20 seconds, but this is still a bit to long for my project. 我用一个小的python脚本将其减少到20秒,但这对于我的项目来说仍然有点长。

Currently i am installing OpenCV to check if this is faster, this process takes around 4 hours so i thought in the meantime i can ask a question here. 目前,我正在安装OpenCV来检查它是否更快,此过程大约需要4个小时,因此我想在此期间我可以在这里提问。

Does anybody have any good idea's or libraries to speed up the process of cropping and re-sizing the images. 是否有人有任何好的主意或库来加快裁剪和调整图像大小的过程。

Following is the python code i used 以下是我使用的python代码

import Image

def crop_image(input_image, output_image, start_x, start_y, width, height):
    """Pass input name image, output name image, x coordinate to start croping, y     coordinate to start croping, width to crop, height to crop """
input_img = Image.open(input_image)
box = (start_x, start_y, start_x + width, start_y + height)
output_img = input_img.crop(box)
output_img.save(output_image +".jpg")
def main():
   crop_image("test.jpg","output", 1000, 0, 4000, 4000)

if __name__ == '__main__': main()

First approach (without sprites) 第一种方法(不包含精灵)

import pyglet
#from pyglet.gl import *

image = pyglet.resource.image('test.jpg')
texture = image.get_texture()
## -- In case you plan on rendering the image, use the following gl set:
#gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
texture.width = 1024
texture.height = 768
texture.get_region(256, 192,771, 576)
texture.save('wham.png') # <- To save as JPG again, install PIL

Second attempt (with sprites, unfinished) 第二次尝试(带有精灵,未完成)

import pyglet, time
start = time.time() #DEBUG
texture = pyglet.image.load('test.jpg')
print('Loaded image in',time.time()-start,'sec') #DEBUG
sprite = pyglet.sprite.Sprite(texture)
print('Converted to sprite in',time.time()-start,'sec') #DEBUG
print(sprite.width) #DEBUG
# Gives: 6000
sprite.scale = 0.5
print('Rescaled image in',time.time()-start,'sec') #DEBUG
print(sprite.width) #DEBUG
# Gives: 3000

Both solutions end up around 3-5 seconds on an extremely slow PC with a shitty mechanical disk running under Windows XP with.. i can't even count the number of applications running including active virus scans etc.. But note that I can't remember how to save a sprite to disk, you need to access to AbstractImage data container within the sprite to get it out. 两种解决方案在一台速度极慢的PC上运行,运行速度慢的PC都在Windows XP下运行约3-5秒。我什至无法计算正在运行的应用程序的数量,包括主动病毒扫描等。但是请注意,我可以记住如何将一个精灵保存到磁盘,您需要访问该精灵内的AbstractImage数据容器才能将其取出。

You will be heavily limited to your disk/memory-card I/O. 您将严重受限于磁盘/存储卡I / O。 My image was 16MB 6000x4000 pixels.. Which i was suprised it whent as fast as 3 seconds to load. 我的图像是16MB 6000x4000像素。当加载速度仅为3秒时,我感到惊讶。

Have you tried jpegtran . 您尝试过jpegtran It provides for lossless cropping of jpeg. 它提供jpeg的无损裁剪。 It should be in the libjpeg-progs package. 它应该在libjpeg-progs软件包中。 I suspect that decoding the image to crop it, then re-encoding it is too much for the SD card to take. 我怀疑对图像进行裁剪以使其裁剪,然后对其进行重新编码对于SD卡而言实在是太多了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM