├── README.md ├── kazetachinu008.jpg ├── kazetachinu008_depth.png ├── pexels-mark-neal-2850726.jpg ├── pexels-mark-neal-2850726_depth.png ├── run_depth_based_visual_haptic.py └── visual_haptic_illust.gif /README.md: -------------------------------------------------------------------------------- 1 | # Depth image based mouse cursor visual haptic 2 | ![](visual_haptic_illust.gif) 3 | ## How to run it. 4 | 1. Install pyqt5. 5 | 6 | 2. Install python modules 7 | ``` 8 | pip install Pillow 9 | pip install numpy 10 | ``` 11 | 12 | For illustration example, 13 | ``` 14 | python run_depth_based_visual_haptic.py --color-image kazetachinu008.jpg --depth-image kazetachinu008_depth.png --most-far-depth 0 15 | ``` 16 | 17 | For photo example, 18 | ``` 19 | python run_depth_based_visual_haptic.py --color-image pexels-mark-neal-2850726.jpg --depth-image pexels-mark-neal-2850726_depth.png --most-far-depth 0 20 | ``` 21 | 22 | ## Example images 23 | The photo image is from [pexels](https://www.pexels.com/ja-jp/). 24 | The illustration image is from [studio ghibli](https://www.ghibli.jp/info/013344/). 25 | -------------------------------------------------------------------------------- /kazetachinu008.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiong-jie-y/depth_based_visual_haptic/7fa8fea37d95eaf8ea2398c8bde47282cebe09f2/kazetachinu008.jpg -------------------------------------------------------------------------------- /kazetachinu008_depth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiong-jie-y/depth_based_visual_haptic/7fa8fea37d95eaf8ea2398c8bde47282cebe09f2/kazetachinu008_depth.png -------------------------------------------------------------------------------- /pexels-mark-neal-2850726.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiong-jie-y/depth_based_visual_haptic/7fa8fea37d95eaf8ea2398c8bde47282cebe09f2/pexels-mark-neal-2850726.jpg -------------------------------------------------------------------------------- /pexels-mark-neal-2850726_depth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiong-jie-y/depth_based_visual_haptic/7fa8fea37d95eaf8ea2398c8bde47282cebe09f2/pexels-mark-neal-2850726_depth.png -------------------------------------------------------------------------------- /run_depth_based_visual_haptic.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt5 import QtCore 3 | from PyQt5.QtWidgets import QApplication, QWidget, QLabel 4 | from PyQt5.QtGui import QCursor, QIcon, QPixmap 5 | 6 | from PIL import Image 7 | import numpy as np 8 | 9 | class VisualHapticImage(QLabel): 10 | def __init__(self, obj, color_image, depth_image, most_far_depth): 11 | super().__init__(obj) 12 | self.setMouseTracking(True) 13 | 14 | # Prepare depth image. 15 | self.depth_image = np.array(Image.open(depth_image)) 16 | self.depth_image[self.depth_image < most_far_depth] = most_far_depth 17 | self.depth_image = (self.depth_image - np.min(self.depth_image)) / (np.max(self.depth_image) - np.min(self.depth_image)) * 255 18 | self.depth_image = self.depth_image.astype(np.int) 19 | 20 | # Prepare cursor images. 21 | cursor = QPixmap('left_ptr.png') 22 | self.scaled_cursors = [cursor.scaled(i * 0.8 + 10, i * 0.8 + 10) for i in range(1, 256)] 23 | 24 | # Prepare color image. 25 | pixmap = QPixmap(color_image) 26 | self.setPixmap(pixmap) 27 | self.resize(pixmap.width(),pixmap.height()) 28 | 29 | def mouseMoveEvent(self, event): 30 | depth = self.depth_image[int(event.y()), int(event.x())] 31 | qcursor = QCursor(self.scaled_cursors[depth]) 32 | self.setCursor(qcursor) 33 | 34 | class VisualHapticExampleApp(QWidget): 35 | def __init__(self, color_image, depth_image, most_far_depth): 36 | super().__init__() 37 | self.label = VisualHapticImage(self, color_image, depth_image, most_far_depth) 38 | 39 | self.setWindowTitle("Visual Haptics Example") 40 | self.setGeometry(0,0, 2000, 1000) 41 | 42 | self.resize(self.label.width(),self.label.height()) 43 | self.show() 44 | 45 | 46 | import click 47 | 48 | @click.command() 49 | @click.option("--color-image") 50 | @click.option("--depth-image") 51 | @click.option("--most-far-depth", default=20000) 52 | def main(color_image, depth_image, most_far_depth): 53 | app = QApplication(sys.argv) 54 | ex = VisualHapticExampleApp(color_image, depth_image, most_far_depth) 55 | sys.exit(app.exec_()) 56 | 57 | if __name__ == '__main__': 58 | main() -------------------------------------------------------------------------------- /visual_haptic_illust.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiong-jie-y/depth_based_visual_haptic/7fa8fea37d95eaf8ea2398c8bde47282cebe09f2/visual_haptic_illust.gif --------------------------------------------------------------------------------