使用双线性插值将2x2矩阵升级到5x5的示例程序.对于这种简单的情况,OpenCV产生的结果在边界处具有伪像.
gy, gx = np.mgrid[0:2, 0:2]
gx = np.float32(gx)
print(gx)
res = cv2.resize(gx,(5,5), fx=0, fy=0, interpolation=cv2.INTER_LINEAR)
print(res)
Run Code Online (Sandbox Code Playgroud)
输出:
[[ 0. 1.]
[ 0. 1.]]
[[ 0. 0.1 0.5 0.89999998 1. ]
[ 0. 0.1 0.5 0.89999998 1. ]
[ 0. 0.1 0.5 0.89999998 1. ]
[ 0. 0.1 0.5 0.89999998 1. ]
[ 0. 0.1 0.5 0.89999998 1. ]]
Run Code Online (Sandbox Code Playgroud)
预期产量:
[[0 0.25 0.5 0.75 1
0 0.25 0.5 0.75 1
0 0.25 0.5 0.75 1
0 0.25 0.5 0.75 1 …Run Code Online (Sandbox Code Playgroud) TEST.CPP:
#include <iostream>
using namespace std;
int main()
{
double pi = 3.14;
cout << "pi:"<< pi << endl;
}
Run Code Online (Sandbox Code Playgroud)
当在cygwin 64位上编译时g++ -mno-sse test.cpp,输出为:
PI:0
但是,如果编译时它可以正常工作g++ test.cpp.
我有GCC版本5.4.0.
输入:
<root>
<aa><aaa/><bbb/><ccc/><ddd/><eee/></aa>
<bb><ggg/></bb>
</root>
Run Code Online (Sandbox Code Playgroud)
理想的输出:
<root>
<aa>aaa<aa>
<aa>bbb<aa>
<aa>ccc<aa>
<aa>ddd<aa>
<aa>eee<aa>
<bb>ggg</bb>
</root>
Run Code Online (Sandbox Code Playgroud)
我想出了简单的xslt,但它只是正确处理,不会创建标签列表.
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- select all elements that doesn't have any child nodes (elements or text etc) -->
<xsl:template match="//*[not(node())]">
<xsl:value-of select="name()"/>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
输出:
<root>
<aa>aaabbbcccdddeee</aa>
<bb>ggg</bb>
</root>
Run Code Online (Sandbox Code Playgroud)
PS它是python脚本的一部分.是否可以在python脚本中使用xslt进行此类转换?或者使用简单的xpath和python逻辑的python解决方案会更好吗?