首发VM手眼标定xml文件点位取出以及转其他格式

embedded/2024/11/30 18:47:56/

首先放出xml文件:"h15.8r1.xml"

<?xml version="1.0" encoding="UTF-8"?>
<CalibInfo><CalibInputParam><CalibParam ParamName="CreateCalibTime" DataType="string"><ParamValue>2024-04-23 19:17:09</ParamValue></CalibParam><CalibParam ParamName="CalibType" DataType="string"><ParamValue>NPointCalib</ParamValue></CalibParam><CalibParam ParamName="TransNum" DataType="int"><ParamValue>9</ParamValue></CalibParam><CalibParam ParamName="RotNum" DataType="int"><ParamValue>3</ParamValue></CalibParam><CalibParam ParamName="CalibErrStatus" DataType="int"><ParamValue>269496395</ParamValue></CalibParam><CalibParam ParamName="TransError" DataType="float"><ParamValue>1.863625</ParamValue></CalibParam><CalibParam ParamName="RotError" DataType="float"><ParamValue>0.99647576</ParamValue></CalibParam><CalibParam ParamName="TransWorldError" DataType="float"><ParamValue>0.24252573</ParamValue></CalibParam><CalibParam ParamName="RotWorldError" DataType="float"><ParamValue>0.12967792</ParamValue></CalibParam><CalibParam ParamName="PixelPrecisionX" DataType="float"><ParamValue>0.12997331</ParamValue></CalibParam><CalibParam ParamName="PixelPrecisionY" DataType="float"><ParamValue>0.13029985</ParamValue></CalibParam><CalibParam ParamName="PixelPrecision" DataType="float"><ParamValue>0.13013655</ParamValue></CalibParam><CalibPointFListParam ParamName="ImagePointLst" DataType="CalibPointList"><PointF><X>1216.51</X><Y>779.13611</Y><R>0</R></PointF><PointF><X>2908.1958</X><Y>787.07654</Y><R>0</R></PointF><PointF><X>4600.999</X><Y>784.99518</Y><R>0</R></PointF><PointF><X>4599.3091</X><Y>1714.9545</Y><R>0</R></PointF><PointF><X>2903.8613</X><Y>1714.681</Y><R>0</R></PointF><PointF><X>1209.8541</X><Y>1706.0481</Y><R>0</R></PointF><PointF><X>1203.0206</X><Y>2635.2905</Y><R>0</R></PointF><PointF><X>2898.4265</X><Y>2643.5801</Y><R>0</R></PointF><PointF><X>4596.5581</X><Y>2643.3296</Y><R>0</R></PointF><PointF><X>3520.8601</X><Y>1254.7367</Y><R>-60</R></PointF><PointF><X>2903.677</X><Y>1714.9659</Y><R>0</R></PointF><PointF><X>2992.3616</X><Y>2481.5713</Y><R>60</R></PointF></CalibPointFListParam><CalibPointFListParam ParamName="WorldPointLst" DataType="CalibPointList"><PointF><X>475.71002</X><Y>-122.05</Y><R>0</R></PointF><PointF><X>475.71002</X><Y>97.949997</Y><R>0</R></PointF><PointF><X>475.71002</X><Y>317.95001</Y><R>0</R></PointF><PointF><X>595.71002</X><Y>317.95001</Y><R>0</R></PointF><PointF><X>595.71002</X><Y>97.949997</Y><R>0</R></PointF><PointF><X>595.71002</X><Y>-122.05</Y><R>0</R></PointF><PointF><X>715.71002</X><Y>-122.05</Y><R>0</R></PointF><PointF><X>715.71002</X><Y>97.949997</Y><R>0</R></PointF><PointF><X>715.71002</X><Y>317.95001</Y><R>0</R></PointF><PointF><X>595.71002</X><Y>97.949997</Y><R>-60</R></PointF><PointF><X>595.71002</X><Y>97.949997</Y><R>0</R></PointF><PointF><X>595.71002</X><Y>97.949997</Y><R>60</R></PointF></CalibPointFListParam></CalibInputParam><CalibOutputParam><CalibParam ParamName="RotDirectionState" DataType="int"><ParamValue>-1</ParamValue></CalibParam><CalibParam ParamName="IsRightCoorA" DataType="int"><ParamValue>-1</ParamValue></CalibParam><PointF ParamName="RotCenterImagePoint" DataType="CalibPointF"><RotCenterImagePointX>3611.1401</RotCenterImagePointX><RotCenterImagePointY>2018.9244</RotCenterImagePointY><RotCenterImageR>-999</RotCenterImageR></PointF><PointF ParamName="RotCenterWorldPoint" DataType="CalibPointF"><RotCenterWorldPointX>261.2843</RotCenterWorldPointX><RotCenterWorldPointY>470.94211</RotCenterWorldPointY><RotCenterWorldR>-999</RotCenterWorldR></PointF><CalibFloatListParam ParamName="CalibMatrix" DataType="FloatList"><ParamValue>-0.00049192336</ParamValue><ParamValue>0.13029745</ParamValue><ParamValue>-261.2843</ParamValue><ParamValue>0.12997237</ParamValue><ParamValue>0.0007893648</ParamValue><ParamValue>-470.94211</ParamValue><ParamValue>-2.5900243e-007</ParamValue><ParamValue>1.2700635e-006</ParamValue><ParamValue>1</ParamValue></CalibFloatListParam></CalibOutputParam>
</CalibInfo>

思路是转json ;json在python里面简直就是字典一样的存在所以直接当字典操作即可;最后读到的点位转成".tup"文件方便hdev助手以及其他调用hdev的程序读取当然稍加修改就可以存成其他格式;上程序:

python">#pip install xmltodictimport os,sys,time,json,xmltodict
from datetime import datetime
def cmd(s="pause"):os.system(s)
def xml_to_json(xml_file_path, json_file_path):try:with open(xml_file_path, 'r') as file:# 从文件中读取XML数据xml_data = file.read()dict_data = xmltodict.parse(xml_data)# 将XML转换为字典json_data = json.dumps(dict_data, indent=4)# 将字典转换为JSON#print(f"JSON{json_data}")with open(json_file_path, 'w') as json_file:# 将JSON数据写入文件json_file.write(json_data)print(f"JSON file has been saved to {json_file_path}")return json_dataexcept Exception as e:print(f" error : {e}")xml_file_path = 'h15.8r1.xml'
json_file_path = 'output.json'
json_data=xml_to_json(xml_file_path, json_file_path)# 调用函数PX=[];
PY=[];
PR=[];         
QX=[];
QY=[];
QR=[];      def get_ppp_params(obj):if isinstance(obj, dict):pic=obj['CalibInfo']['CalibInputParam']['CalibPointFListParam'][0]['PointF']#图像点wor=obj['CalibInfo']['CalibInputParam']['CalibPointFListParam'][1]['PointF']#物理点print('\n\n\n')for item in pic:print(f"{item};  {item['X']}  {item['Y']}  {item['R']}")PX.append(item['X']);PY.append(item['Y']);PR.append(item['R']);print('\n\n\n')for item in wor:print(f"{item};  {item['X']}  {item['Y']}  {item['R']}")QX.append(item['X']);QY.append(item['Y']);QR.append(item['R']);#with open('ppp.json', 'w') as json_file:#    json_file.write(f"{iii}")data = json.loads(json_data)get_ppp_params(data)# 取出来了 显示一下
print(f"""
{PX},{PY},{PR}, /  
{QX}, {QY}, {QR}  """)print('\n\n\n')import halcon as haha.write_tuple(PX,'PX.tup')
ha.write_tuple(PY,'PY.tup')
ha.write_tuple(PR,'PR.tup')
ha.write_tuple(QX,'QX.tup')
ha.write_tuple(QY,'QY.tup')
ha.write_tuple(QR,'QR.tup')cmd(s="pause")

好了 运行起来文件就会保存到程序目录;

其他语言 比如C++

我有一个损招; 不说了看程序:

#include <iostream>
#include<Python.h>
int main()
{Py_Initialize();//Py_Finalize();PyRun_SimpleString("print('C++ call python!')");PyRun_SimpleString("import os");//PyRun_SimpleString("os.system('pause')");PyRun_SimpleString("from tkinter import *");PyRun_SimpleString("import tkinter as tk");//PyRun_SimpleString("window = Tk()");PyRun_SimpleString("def callback() :print('click me!')");//import tkinter as tkPyRun_SimpleString("b = tk.Button(window, text='hj', command=callback).pack()");PyRun_SimpleString("window.mainloop()");
}

你要非说这还是python不是C++ 我要告诉你 那你自己想办法;

你如果是C# 那么

        public string _CMD(string strInput){string strOuput;Process p = new Process();p.StartInfo.FileName = "cmd.exe";//设置要启动的应用程序p.StartInfo.UseShellExecute = false;//是否使用操作系统shell启动p.StartInfo.RedirectStandardInput = true;// 接受来自调用程序的输入信息p.StartInfo.RedirectStandardOutput = true;//输出信息p.StartInfo.RedirectStandardError = true;// 输出错误p.StartInfo.CreateNoWindow = true;//不显示程序窗口//  p.StartInfo.CreateNoWindow = false; //显示程序窗口p.Start();//启动程序p.StandardInput.WriteLine(strInput + "&exit");//向cmd窗口发送输入信息p.StandardInput.AutoFlush = true;strOuput = p.StandardOutput.ReadToEnd(); //获取输出信息p.WaitForExit(); //等待程序执行完退出进程p.Close();return strOuput;}// string str = _CMD(@"python xxx.py");

这样能用; 我更倾向于pythonnet 不过C#里面到处 dynamic 感觉不太好;

当然如果你是JS那么js比python灵活 我就不搞笑了;


http://www.ppmy.cn/embedded/141811.html

相关文章

GAMIT 单北斗sV antenna offsets for SVN c232 not found in antmod.dat

FATAL:241125:1153:10.0 MoDEL/setup: sV antenna offsets for SVN c232 not found in antmod.dat 下载antmod.dat ,进行更新。 ftp下载地址&#xff0c;garner.ucsd.edu

矩阵重构——reshape函数

r e s h a p e reshape reshape函数可以用于矩阵的重构 用法&#xff1a; r e s h a p e ( a , m , n ) reshape(a,m,n) reshape(a,m,n)&#xff0c;将 a a a转化为一个 m m m行 n n n列的矩阵 注意&#xff1a;若重构前 a a a为一个 l l l行 k k k列的矩阵&#xff0c;&#x…

【动手学电机驱动】STM32-FOC(8)MCSDK Profiler 电机参数辨识

STM32-FOC&#xff08;1&#xff09;STM32 电机控制的软件开发环境 STM32-FOC&#xff08;2&#xff09;STM32 导入和创建项目 STM32-FOC&#xff08;3&#xff09;STM32 三路互补 PWM 输出 STM32-FOC&#xff08;4&#xff09;IHM03 电机控制套件介绍 STM32-FOC&#xff08;5&…

webGL入门教程_02顶点着色器与片元着色器

顶点着色器与片元着色器详解 在现代图形渲染中&#xff0c;GPU 的着色器程序&#xff08;Shaders&#xff09;扮演着至关重要的角色。顶点着色器&#xff08;Vertex Shader&#xff09;和片元着色器&#xff08;Fragment Shader&#xff09;是图形渲染管线中的两个核心部分&am…

Prophet时间序列算法总结及python实现案例

目录 一、prophet理论总结二、python导入模块方式三、python实现案例3.1帮助信息3.2 案例 四、参考学习 一、prophet理论总结 prophet模型是facebook开源的一个时间序列预测算法。[1][2]&#xff0c;该算法主要为处理具有周期性、趋势变化以及缺失值和异常值的时间序列数据而设…

高级java每日一道面试题-2024年11月25日-JVM篇-说说Java对象创建过程?

如果有遗漏,评论区告诉我进行补充 面试官: 说说Java对象创建过程? 我回答: 在Java高级面试中&#xff0c;Java对象的创建过程是一个常被提及的重要话题。以下是对Java对象创建过程的详细解析&#xff1a; 一、Java对象创建的基本步骤 检查类是否加载&#xff1a; 当需要创…

C++设计模式(模板模式)

一、介绍 1.动机 在软件构建过程中&#xff0c;对于某一项任务&#xff0c;它常常有稳定的整体操作结构&#xff0c;但各个子步骤却有很多改变的需求&#xff0c;或者由于固有的原因&#xff08;比如框架与应用之间的关系&#xff09;而无法和任务的整体结构同时实现。 如何…

爬虫技术全解析:从入门到精通

引言 在互联网时代&#xff0c;数据已成为最宝贵的资源之一。爬虫技术作为一种自动化获取网页数据的工具&#xff0c;被广泛应用于数据采集、信息聚合、市场分析等多个领域。本文将带你从零开始&#xff0c;全面了解爬虫技术&#xff0c;包括其基本原理、常用工具、编程实践以…