analitics

Pages

Monday, June 13, 2022

Blender 3D and python scripting - part 016.

On this day, I will digress from the series of tutorials started and presented and show you how to install other python packages in Blender 3D.
Go to the bin folder where the python is install, see my path of Blender 3D.
C:\blender-3.3.0-alpha+master.add1da52ad78-windows.amd64-release\3.3\python\bin
Use these commands in to window command shell to install OpenCv python module.
python.exe -m ensurepip
python.exe -m pip install --upgrade pip
python.exe -m pip install opencv-python 
python.exe -m pip install opencv-contrib-python
Run in the blender script area these commands, in order to see if this python package working.
import cv2
cv2.version
You can create a simple script and test it, see the next example:
import numpy as np
import cv2
  
# Creating a black image with 3 channels
# RGB and unsigned int datatype
img = np.zeros((400, 400, 3), dtype = "uint8")
  
# Creating line
cv2.line(img, (21, 167), (100, 99), (0, 0, 255), 8)
  
cv2.imshow('dark', img)
  
# Allows us to see image
# until closed forcefully
cv2.waitKey(0)
cv2.destroyAllWindows()
You can see a screenshot with this python script: