org.openpnp.vision.pipeline.stages.MaskRectangle
文章目录
- org.openpnp.vision.pipeline.stages.MaskRectangle
- 功能
- 参数
- 例子
- 效果
- END
org.openpnp.vision.pipeline.stages.MaskRectangle
功能
对当前工作图像应用矩形掩码
参数
| 参数名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
width | int | 100 | 矩形掩码的宽度(像素)。矩形以图像中心为中心。 |
height | int | 100 | 矩形掩码的高度(像素)。矩形以图像中心为中心。 |
例子
importcv2importnumpy as np def generate_test_image(output_path="mask_rectangle_test.png",size=(640,480)):# 纯蓝色背景 (BGR: 255,0,0)img=np.full((size[1],size[0],3),(255,0,0),dtype=np.uint8)# 红色圆形(圆心(200,150),半径60)cv2.circle(img,(200,150),60,(0,0,255),-1)# 绿色矩形(左上角(100,300),右下角(200,400))cv2.rectangle(img,(100,300),(200,400),(0,255,0), -1)# 黄色三角形 (三个顶点)pts=np.array([[500,100],[600,200],[400,200]], np.int32)cv2.fillPoly(img,[pts],(0,255,255))cv2.imwrite(output_path, img)print(f"测试图片已生成: {output_path}")if__name__=="__main__":generate_test_image()<cv-pipeline><stages><cv-stageclass="org.openpnp.vision.pipeline.stages.ImageRead"name="read"enabled="true"file="D:\3rd\openpnp_prj\openpnp-official\openpnp-test-images\my_test\mask_rectangle_test.png"color-space="Bgr"handle-as-captured="false"/><cv-stageclass="org.openpnp.vision.pipeline.stages.MaskRectangle"name="maskRect"enabled="true"width="400"height="200"/><cv-stageclass="org.openpnp.vision.pipeline.stages.ImageWrite"name="save"enabled="true"file="output_masked_rectangle.png"/></stages></cv-pipeline>