MVEL2.0模板(Orb Tags)

MVEL 2.0 Orb Tags
Attention

For MVEL 1.2 and 1.3, goto the Templating Guide.

This page contains a list of all orb-tags available out-of-the-box in the MVEL 2.0 templating engine.

@{} Expression Orb

The expression orb is the most rudimentary form of orb-tag. It contains a value expression which will be evaluated to a string, and appended to the output template. For example:

Hello, my name is @{person.name}

@code{} Silent Code Tag

The silent code tag allows you to execute MVEL expression code in your template. It does not return a value and does not affect the formatting of the template in any way.

@code{age = 23; name = 'John Doe'}
@{name} is @{age} years old.

This template will evaluate to: John Doe is 23 years old.

@if{}-@else{} Control Flow Tags

The @if{} and @else{} tags provide full if-then-else functionality in MVEL Templates. For example:

@if{foo != bar}
   Foo not a bar!
@else{bar != cat}
   Bar is not a cat!
@else{}
   Foo may be a Bar or a Cat!
@end{}
Termination of blocks

All blocks in MVEL Templates must be terminated with an @end{} orb, except in cases of an if-then-else structure, where @else{} tags denote the termination of the previous control statement.

@foreach{} Foreach iteration

The foreach tag allows you to iterate either collections or arrays in your template. Note: that the syntax for foreach has changed in MVEL Templates 2.0 to standardize the foreach notation with that of the MVEL language itself.

@foreach{item : products} 
 - @{item.serialNumber}
@end{}

MVEL 2.0 requires you specify an iteration variable. While MVEL 1.2 assumed the name item if you did not specify an alias, this has been dropped due to some complaints about that default action.

Multi-iteration

You can iterate more than one collection in a single foreach loop at one time by comma-separating the iterations:

@foreach{var1 : set1, var2 : set2}
  @{var1}-@{var2}
@end{}

Delimiting

You can automatically add a text delimiter to an iteration by specifying the iterator in @end{} tag.

@foreach{item : people}@{item.name}@end{', '}

This would return something like: John, Mary, Joseph.

@include{} Include Template File

You may include a template file into an MVEL template using this tag.

@include{'header.mv'}

This is a test template.

You may also execute an MVEL expression inside an include tag by adding a semicolon after the template name:

@include{'header.mv'; title='Foo Title'}

@includeNamed{} Include a Named Template

Named templates are templates that have been precompiled and passed to the runtime via a TemplateRegistry, or templates that have been declared within the template itself. You simply include

You may also execute MVEL code in an @includeNamed{} tag, just as with the @include{} tag.

@includeNamed{'fooTemplate'}
@includeNamed{'footerTemplate', showSomething=true}

@declare{} Declare a Template

In addition to including external templates from external files, and passing them in programmatically, you can declare a template from within a template. Which allows you to do things like this:

@declare{'personTemplate'}
 Name: @{name}
 Age:  @{age}
@end{}

@includeNamed{'personTemplate'; name='John Doe'; age=22}

@comment{} Comment tag

The comment tag allows you add an invisible comment to the template. For example:

@comment{
  This is a comment
}
Hello: @{name}!
对于ORB(Oriented FAST and Rotated BRIEF)模板匹配在Java中的实现,你可以使用OpenCV库来完成。以下是一个简单的示例代码: ```java import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfDMatch; import org.opencv.core.MatOfKeyPoint; import org.opencv.core.MatOfPoint; import org.opencv.core.Point; import org.opencv.core.Rect; import org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.features2d.Features2d; import org.opencv.features2d.ORB; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class ORBTemplateMatching { public static void main(String[] args) { // 加载OpenCV库 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // 读取输入图像和模板图像 Mat inputImage = Imgcodecs.imread("input.jpg"); Mat templateImage = Imgcodecs.imread("template.jpg"); // 创建ORB对象 ORB orb = ORB.create(); // 在输入图像和模板图像中检测特征点和计算描述符 MatOfKeyPoint keypointsInput = new MatOfKeyPoint(); Mat descriptorsInput = new Mat(); orb.detectAndCompute(inputImage, new Mat(), keypointsInput, descriptorsInput); MatOfKeyPoint keypointsTemplate = new MatOfKeyPoint(); Mat descriptorsTemplate = new Mat(); orb.detectAndCompute(templateImage, new Mat(), keypointsTemplate, descriptorsTemplate); // 使用暴力匹配器进行特征点匹配 MatOfDMatch matches = new MatOfDMatch(); Features2d.matchDescriptors(descriptorsInput, descriptorsTemplate, matches); // 绘制匹配结果 Mat outputImage = new Mat(); Features2d.drawMatches(inputImage, keypointsInput, templateImage, keypointsTemplate, matches, outputImage, Scalar.all(-1), Scalar.all(-1), new MatOfByte(), Features2d.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS); // 显示输出图像 Imgcodecs.imwrite("output.jpg", outputImage); } } ``` 请确保你已经正确安装了OpenCV并将其配置到Java项目中。此示例代码中假设输入图像为"input.jpg",模板图像为"template.jpg",你需要根据实际情况修改文件路径。运行代码后,你将得到匹配结果的输出图像"output.jpg"。 这只是一个简单的示例,你可以根据自己的需求进行更多的调整和改进。希望对你有帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值