HalconDotNet.HTupleAccessException:“'Illegal operation on Tuple' when accessing 'HalconDotNet.HTupleDouble'”

HalconDotNet.HTupleAccessException:“'Illegal operation on Tuple' when accessing 'HalconDotNet.HTupleDouble'”

TupleSelect(hv_MatchingObjIdx)数据是double,再转int或者float

imgInfoClass.x = (int)hv_ModelColumn.TupleSelect(hv_MatchingObjIdx).D; //I is integer
imgInfoClass.y = (int)hv_ModelRow.TupleSelect(hv_MatchingObjIdx).D; //D is double type



int x = (int)hv_ModelColumn.TupleSelect(hv_MatchingObjIdx).D; //I is integer
int y = (int)hv_ModelRow.TupleSelect(hv_MatchingObjIdx).D; //D is double type



float x = (float)hv_ModelColumn.TupleSelect(hv_MatchingObjIdx).D; //I is integer
float y = (float)hv_ModelRow.TupleSelect(hv_MatchingObjIdx).D; //D is double type



double不需要转换

double x = hv_ModelColumn.TupleSelect(hv_MatchingObjIdx).D; //I is integer
double y = hv_ModelRow.TupleSelect(hv_MatchingObjIdx).D; //D is double type

 

* Matching 15: BEGIN of generated code for model initialization
*set_system ('border_shape_models', 'true')
* Matching 15: Obtain the model image
read_image (Image, 'D:/TPS_Work/Work_Project/Ix项目/pics/1b445864-9d45-4ed5-b39c-0a2b23034a71.jpg')
* Matching 15: build the ROI from basic regions
*gen_rectangle1 (ModelRegion, 623.053, 569.565, 782.423, 724.185)
* Matching 15: reduce the model template
*reduce_domain (Image, ModelRegion, TemplateImage)
* Matching 15: create the shape model
*create_shape_model (TemplateImage, 3, rad(0), rad(30), rad(1.0592), ['point_reduction_high','no_pregeneration'], 'use_polarity', [35,47,125], 4, ModelId)
* Matching 15: get the model contour for transforming it later into the image


*get_shape_model_contours (ModelContours, ModelId, 1)

*write_shape_model (ModelId, 'D:/halcon_project/mod1.shm')

read_shape_model('D:/halcon_project/mod1.shm',ModelId)
get_shape_model_contours (ModelContours, ModelId, 1)
* Matching 15: END of generated code for model initialization
* Matching 15: BEGIN of generated code for model application
* Matching 15: the following operations are usually moved into
* Matching 15: that loop where the aquired images are processed
* Matching 15: Find the model

find_shape_model (Image, ModelId, rad(0), rad(30), 0.3, 27, 0.5, 'least_squares', [3,1], 0.9, ModelRow, ModelColumn, ModelAngle, ModelScore)
* Matching 15: transform the model contours into the detected positions
for MatchingObjIdx := 0 to |ModelScore| - 1 by 1
    hom_mat2d_identity (HomMat)
    hom_mat2d_rotate (HomMat, ModelAngle[MatchingObjIdx], 0, 0, HomMat)
    hom_mat2d_translate (HomMat, ModelRow[MatchingObjIdx], ModelColumn[MatchingObjIdx], HomMat)
    affine_trans_contour_xld (ModelContours, TransContours, HomMat)
    dev_display (TransContours)
    
    gen_rectangle1 (ModelRegion, ModelRow[MatchingObjIdx]-75, ModelColumn[MatchingObjIdx]-75, ModelRow[MatchingObjIdx]+75, ModelColumn[MatchingObjIdx]+75)
* Matching 15: reduce the model template
    reduce_domain (Image, ModelRegion, TemplateImage)
    crop_domain (TemplateImage, ImagePart)
    write_image (ImagePart, 'jpg', 0, MatchingObjIdx +'.jpg')
    
endfor
* Matching 15: Clear model when done
* dev_open_window(0,0,300,300,'black',WindowHandle1)
clear_shape_model (ModelId)
* Matching 15: END of generated code for model application

 

posted @ 2025-09-25 08:54  txwtech  阅读(8)  评论(1)    收藏  举报