Skip to content

Commit

Permalink
resolved OpenCVImageViewer import error and added close method for gy…
Browse files Browse the repository at this point in the history
…m viewer compatibility
  • Loading branch information
koulanurag committed Jan 5, 2020
1 parent 425d407 commit 3f01f7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dm2gym/envs/dm_suite_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def render(self, mode='human', **kwargs):
from gym.envs.classic_control import rendering
self.viewer = rendering.SimpleImageViewer(maxwidth=1024)
else:
from dm2gym import OpenCVImageViewer
from . import OpenCVImageViewer
self.viewer = OpenCVImageViewer()
self.viewer.imshow(img)
return self.viewer.isopen
Expand Down
6 changes: 5 additions & 1 deletion dm2gym/envs/opencv_image_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class OpenCVImageViewer():
This class is meant to be a drop-in replacement for
`gym.envs.classic_control.rendering.SimpleImageViewer`
"""

def __init__(self, *, escape_to_exit=False):
"""Construct the viewing window"""
self._escape_to_exit = escape_to_exit
Expand All @@ -29,8 +30,11 @@ def imshow(self, img):
# Listen for escape key, then exit if pressed
if cv2.waitKey(1) in [27] and self._escape_to_exit:
exit()

@property
def isopen(self):
"""Is the window open?"""
return self._isopen

def close(self):
pass

0 comments on commit 3f01f7a

Please sign in to comment.