1

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

6
  • 4
    That's a networking socket error, I can't see how you'd get it here. Are you reading/writing the image on a network? Commented Mar 24, 2015 at 7:27
  • No. I am reading/writing the image on my local computer drive, not on a network. Commented Mar 25, 2015 at 0:21
  • Strange. Can you post the actual traceback? Commented Mar 25, 2015 at 0:43
  • I have just attached the actual traceback (see on the post) Commented Mar 25, 2015 at 2:07
  • It looks like PyScripter is using rpyc (a networking protocol), which is giving the error. Are you running the script from PyScripter? Can you try running it in a command window instead? Commented Mar 25, 2015 at 2:29

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks figs. When I convert the image into PNG file it can run but has not created the new image after running gaus=cv2.imwrite("new.tif",gaussian). When I use cv2.imshow ("new_image", gaussian) it has error: error:(-215) size.width>0 && size.height>0 in function cv::imshow.
See my edit for working code. Make sure the image you are trying to open exists.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.