Skip to content

fixed deprecated tostring() and fromstring() error #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions SimpleCV/ImageClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def __init__(self, source = None, camera = None, colorSpace = ColorSpace.UNKNOWN
self._pil = webpImage.convert("RGB")
self._bitmap = cv.CreateImageHeader(self._pil.size, cv.IPL_DEPTH_8U, 3)
self.filename = source
cv.SetData(self._bitmap, self._pil.tostring())
cv.SetData(self._bitmap, self._pil.tobytes())
cv.CvtColor(self._bitmap, self._bitmap, cv.CV_RGB2BGR)

else:
Expand All @@ -1072,7 +1072,7 @@ def __init__(self, source = None, camera = None, colorSpace = ColorSpace.UNKNOWN
except:
self._pil = pil.open(self.filename).convert("RGB")
self._bitmap = cv.CreateImageHeader(self._pil.size, cv.IPL_DEPTH_8U, 3)
cv.SetData(self._bitmap, self._pil.tostring())
cv.SetData(self._bitmap, self._pil.tobytes())
cv.CvtColor(self._bitmap, self._bitmap, cv.CV_RGB2BGR)

#TODO, on IOError fail back to PIL
Expand All @@ -1099,7 +1099,7 @@ def __init__(self, source = None, camera = None, colorSpace = ColorSpace.UNKNOWN
#from the opencv cookbook
#http://opencv.willowgarage.com/documentation/python/cookbook.html
self._bitmap = cv.CreateImageHeader(self._pil.size, cv.IPL_DEPTH_8U, 3)
cv.SetData(self._bitmap, self._pil.tostring())
cv.SetData(self._bitmap, self._pil.tobytes())
self._colorSpace = ColorSpace.BGR
cv.CvtColor(self._bitmap, self._bitmap, cv.CV_RGB2BGR)
#self._bitmap = cv.iplimage(self._bitmap)
Expand Down Expand Up @@ -1904,7 +1904,7 @@ def getPIL(self):
if (not self._pil):
rgbbitmap = self.getEmpty()
cv.CvtColor(self.getBitmap(), rgbbitmap, cv.CV_BGR2RGB)
self._pil = pil.fromstring("RGB", self.size(), rgbbitmap.tostring())
self._pil = pil.frombytes("RGB", self.size(), rgbbitmap.tostring())
return self._pil


Expand Down Expand Up @@ -4889,7 +4889,7 @@ def findBarcode(self,doZLib=True,zxing_path=""):
#configure zbar
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
raw = self.getPIL().convert('L').tostring()
raw = self.getPIL().convert('L').tobytes()
width = self.width
height = self.height

Expand Down Expand Up @@ -6213,7 +6213,7 @@ def _surface2Image(self,surface):
return retVal.toBGR().transpose()

def _image2Surface(self,img):
return pg.image.fromstring(img.getPIL().tostring(),img.size(), "RGB")
return pg.image.fromstring(img.getPIL().tobytes(),img.size(), "RGB")
#return pg.surfarray.make_surface(img.toRGB().getNumpy())

def toPygameSurface(self):
Expand Down Expand Up @@ -6251,7 +6251,7 @@ def toPygameSurface(self):
:py:meth:`blit`

"""
return pg.image.fromstring(self.getPIL().tostring(),self.size(), "RGB")
return pg.image.fromstring(self.getPIL().tobytes(),self.size(), "RGB")


def addDrawingLayer(self, layer = None):
Expand Down