11.3.01. open cv to gh: string to geometry data
This is a custom workflow tutorial- the workflow enables live data transfer between Python-OpenCV and Grasshopper. The first part of the tutorial goes over setting up a data transfer link using a data transfer protocol over IP. The second part goes over methods of processing string type of data in Grasshopper and converting strings to geometry input data. The third and final part explains projective uses and applications of this workflow and of computer vision in Grasshopper in general.
Before following this tutorial, make sure you have Python, PyCharm and Anaconda installed. If not, you can follow this tutorial.
As well, you should already have a Conda environment configured, and OpenCV installed (recommended version: 126.96.36.199). If not, you can follow this tutorial. As well, if you need a refresher on how to set up a PyCharm project, you can watch this tutorial.
In Grasshopper, make sure you have the gHOWL plugin installed.
2. Steps to establish live data stream
First, we need to set up parallel instances of PyCharm and Grasshopper.
1. Download the Class Files.
2. Open PyCharm
3. In PyCharm > Open Folder > select the ‘OpenCV’ folder from your class files pack
4. Open any script. Find and paste your own IP address in the IP variable at line 7. (to find your IP address > right-click on wi-fi sign > properties > IPv4)
1. Open the “client-server model” GH file.
2. Paste your own IP address in the panel.
3. Check to make sure that the UDP component is listening to port.
In PyCharm, click shift+F10 or right-click to run the script you want to send data from.
In Grasshopper, check if the UDP component is notifying you of new messages being received. If yes, the connection is established, and data is being streamed live from Python-OpenCV to GH.
The client-server model takes string data from Python and passes string data to GH in a panel. The “de-stringify” custom component breaks down the data stream into data components that can be then further processed into GH geometry.
This exercise is using Python version 3.6.0.