user30985
user30985

Reputation: 683

Gaussian filtering opencv_python error

I use Gaussian filtering for my image and when running the following code, it has error[Errno 10054] Ann existing connection was forcibly closed by the remote host

import cv2
import numpy as np
import arcpy
img = cv2.imread("0109.tif")
gaussian= cv2.GaussianBlur(img,(1,1),1)
gaus=cv2.imwrite("new.tif",gaussian)

How to fix this error. Thanks.

Below is the traceback

__call__        C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\netref.py 123 
syncreq     C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\netref.py 45
sync_request    C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\protocol.py   343
serve       C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\protocol.py   305
 _recv      C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\protocol.py   265 
 recv       C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\channel.py    36
read        C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\stream.py 105
exceptions.EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host    

enter image description here

Upvotes: 1

Views: 3222

Answers (1)

101
101

Reputation: 8989

The networking error is just a red herring thrown by PyScripter as it appears to use networking to run scripts.

The actual error seems to be to do with OpenCV not liking your image file. I can recreate a crash if I use Photoshop to make a TIFF image with JPEG compression and feed that into your script. A quick Google shows others have had somewhat similar issues with JPEG compressed TIFFs and OpenCV, so I'm guessing this is the cause of your problem. Try using an uncompressed TIFF image, or even better use a widely used lossless image format such as PNG.

Edit: This code works for me to blur, show, and save the image (provided image.png exists!):

import cv2
import numpy as np

img = cv2.imread("image.png")
gaussian = cv2.GaussianBlur(img,(5,5),1)
cv2.imshow("Image", gaussian)
cv2.waitKey()
cv2.imwrite("blurred.png", gaussian)

Upvotes: 2

Related Questions