Python Sample Usage Guide
This section introduces how to configure and run Python samples of Mech-Vision SDK.
Prerequisites
-
SDK environment setup has been completed.
-
Python 3.8 or later.
-
The
mmind_visionpackage is installed (see Python environment setup). -
Mech-Vision is installed and can run properly.
Sample Overview
Python samples are located in development/python/examples/ as standalone files:
| Sample file | Description |
|---|---|
|
Open, close, save, and rename solutions; get solution information and project information lists. |
|
Run projects and get output data (pick point poses). |
|
Operate project data storage and read/write stored data. |
|
Get parameter recipe lists and switch the current parameter recipe. |
|
Get and modify communication configurations of a solution (TCP/IP, Modbus, and so on). |
|
Get camera status information in a solution, such as connection status, temperature, and transfer rate. |
|
Read and write global variables in a solution (integer, floating-point, string, queue, and so on). |
|
Get Step information, pin Step output ports, and get Step output data (such as point poses) after running a project. |
|
Read and set Step parameters in JSON format. |
Run Samples
-
Ensure that Mech-Vision is running.
-
Update the solution path in the sample file by replacing the default path with the actual one:
path = "D:/path/to/your/solution" -
Run the sample in a command line:
python solution_basic.py
Code Examples
Open a Solution and Get Project Information (solution_basic.py)
import mmind_vision
from mmind_vision import *
def main():
# Open a solution
solution = Solution()
solution.open("D:/data/vision_sdk_example", "", "")
# Get solution information
solution_info = solution.get_info()
print(f"Solution: {solution_info.name}")
print(f"Path: {solution_info.path}")
# Get project information list
project_infos = solution.get_all_project_infos()
for info in project_infos:
print(f" Project: {info.name}, Running: {info.is_running}")
# Save and close the solution
solution.save()
solution.close()
if __name__ == '__main__':
mmind_vision.initialize()
main()
mmind_vision.uninitialize()
Run a Project and Get Output Data (project_basic.py)
import mmind_vision
from mmind_vision import *
import json
def main():
solution = Solution()
solution.open("D:/data/vision_sdk_example", "", "")
# Get the first project name
project_infos = solution.get_all_project_infos()
project = Project(project_infos[0].name)
# Run the project (wait until it finishes)
project_result = project.run(
ProjectRunWaitState.Finished, "request_1")
# Parse output data (pick point poses)
output = json.loads(project_result.output_json)
pick_points = output.get("workobject_data", {}).get("pick_points", [])
print(f"Pick points count: {len(pick_points)}")
if __name__ == '__main__':
mmind_vision.initialize()
main()
mmind_vision.uninitialize()
Read and Set Step Parameters (step_props.py)
import mmind_vision
from mmind_vision import *
import json
def main():
solution = Solution()
solution.open("D:/data/vision_sdk_example", "", "")
step = Step("3D Matching_1", "Matching")
# Read step parameters
names_json = json.dumps(["confidenceThreshold"])
props_json = step.get_properties_json(names_json)
props = json.loads(props_json)
print(f"Confidence threshold: {props['confidenceThreshold']}")
# Set step parameters
new_props = json.dumps({"confidenceThreshold": 0.8})
step.set_properties_json(new_props)
if __name__ == '__main__':
mmind_vision.initialize()
main()
mmind_vision.uninitialize()