如何用GPU加速OpenCV Python的imread/imwrite及性能优化疑问
图片分割性能优化问题(Ubuntu + OpenCV/Pillow-SIMD)
核心背景与GPU加速疑问
在Ubuntu系统上使用OpenCV Python 4.8.1进行图片分割操作,当前性能表现不佳,希望优化提速。已下载OpenCV 4.8.1源码并完成编译,通过cv2.cuda.getCudaEnabledDeviceCount()确认GPU计数为1,但不清楚如何让imread/imwrite调用GPU进行加速。
我的OpenCV Python代码如下:
# Load and split the image using OpenCV image = cv2.imread(request_data.file_location) height, width, _ = image.shape overlap = 100 # Adjust the overlap size as needed size = 500 results = [] for i in range(0, height, size - overlap): for j in range(0, width, size - overlap): img_part = image[i:i + size, j:j + size] output_file = os.path.join(output_dir, f"result_{i}_{j}.jpg") cv2.imwrite(output_file, img_part) results.append(output_file) return {"path": results}
多进程优化可行性疑问
若无法通过GPU加速imread/imwrite(当前仅占用1核CPU),是否可以使用多进程优化?另外,多进程是不是无法提升imread()的性能?
Pillow-SIMD性能结果疑问
尝试了Pillow-SIMD 9.0.0.post1并将压缩级别设为1,但性能比OpenCV更慢:OpenCV读取耗时2秒、写入耗时2秒;Pillow-SIMD读取耗时1秒、写入耗时3秒。这一结果是否合理?我查阅资料发现多数场景下Pillow-SIMD比OpenCV更快。
我的Pillow代码如下:
image = Image.open(request_data.file_location) # Define split parameters size = 500 overlap = 100 results = [] for i in range(0, image.height, size - overlap): for j in range(0, image.width, size - overlap): # Crop and save the image using Pillow img_part = image.crop((j, i, j + size, i + size)) output_file = os.path.join(output_dir, f"result_{i}_{j}.jpg") img_part.save(output_file) results.append(output_file)
内容的提问来源于stack exchange,提问作者Dennys
相关产品推荐
相关产品推荐

