shape based matching

时间: 2023-04-30 16:04:06 浏览: 66
形状匹配算法,是一种基于形状特征的图像匹配方法,主要通过对图像的形状特征进行提取,计算两个对象之间形状相似度,进而实现图像匹配的目的。常见的形状特征包括边缘、轮廓、角点等。形状匹配算法常被应用于物体识别、机器视觉等领域。
相关问题

fastest_image_pattern_matching shape_based_matching

最快的图像模式匹配算法可能就是基于形状的匹配(shape-based matching)了。这种算法的基本思路是先用特征提取算法将图像中的物体特征提取出来,比如轮廓、边缘、角点等等,然后求出各个特征之间的相对位置关系和大小关系,从而得到该物体的特征描述子。接着,对于任意一张原始图像,也可以用相同的特征提取算法得到它的物体特征描述子,然后就可以通过比较两个物体特征描述子的相似程度,来判断它们是否匹配。 相比于基于像素的匹配算法,基于形状的匹配算法具有更强的鲁棒性和适用性,因为它能够有效地处理物体旋转、缩放、变形、遮挡以及光照变化等问题。而且在对大规模图像数据库进行查询时,基于形状的匹配算法也能够达到较高的检索精度和速度。 不过,需要注意的是,基于形状的匹配算法也存在一些问题,比如可能会出现误匹配和漏匹配的情况,因为不同物体可能具有相似的形状特征。此外,基于形状的匹配算法的运算复杂度也相对较高,需要消耗较多的计算资源。

opencv find_shape_model

The `find_shape_model` function in OpenCV is used for finding a shape model from a set of training images. It is part of the Shape Matching module in OpenCV, which provides tools for matching shapes based on their contour and other features. The `find_shape_model` function takes as input a set of training images, which are typically binary images with the object of interest represented as a white shape on a black background. The function then computes a shape model based on the contours of the objects in the training images. The shape model can be used for shape matching, which involves finding the best match between a given image and the shape model. This can be useful for object recognition and tracking. To use the `find_shape_model` function, you first need to create a ShapeContextDistanceExtractor object, which defines the distance metric used for shape matching. You then call the `find_shape_model` function, passing in the training images and the ShapeContextDistanceExtractor object. Here's an example of how to use the `find_shape_model` function: ``` import cv2 # Load training images img1 = cv2.imread("train1.png", cv2.IMREAD_GRAYSCALE) img2 = cv2.imread("train2.png", cv2.IMREAD_GRAYSCALE) img3 = cv2.imread("train3.png", cv2.IMREAD_GRAYSCALE) # Create ShapeContextDistanceExtractor object sc_extractor = cv2.createShapeContextDistanceExtractor() # Find shape model from training images shape_model = cv2.findShapeModel([img1, img2, img3], sc_extractor) ``` In this example, we load three training images and create a ShapeContextDistanceExtractor object. We then call the `findShapeModel` function, passing in the three training images and the ShapeContextDistanceExtractor object. The function returns a shape model, which can be used for shape matching.
阅读全文

相关推荐

* This example shows how to use shape-based matching * in order to find a model region and use it for * further tasks. * Here, the additional task consists of reading text * within a certain region, wherefore the image has * to be aliged using the matching transformation. * * Initialization. dev_update_window ('off') dev_close_window () * Initialize visualization. read_image (ReferenceImage, 'board/board_01') get_image_size (ReferenceImage, Width, Height) initialize_visualization (Width / 2, Height / 2, WindowHandle, WindowHandleText) disp_continue_message (WindowHandle, 'black', 'true') disp_description_text (WindowHandleText) * * Define ROIs: * ROI for the shape model. dev_set_window (WindowHandle) dev_display (ReferenceImage) gen_rectangle1 (ROIModel, 60, 535, 185, 900) dev_display (ROIModel) * ROI for the text. gen_rectangle1 (ROIText, 445, 585, 590, 765) dev_display (ROIText) disp_model_message (WindowHandle) stop () * * Prepare the shape-based matching model. reduce_domain (ReferenceImage, ROIModel, ModelImage) * Create shape model and set parameters (offline step). create_generic_shape_model (ModelHandle) * Train the shape model. train_generic_shape_model (ModelImage, ModelHandle) * * Prepare the text model. create_text_model_reader ('auto', 'Industrial_0-9A-Z_Rej.omc', TextModel) * * We look for the reference transformation which we will need * for the alignment. We can extract it by finding the instance * on the reference image. * Set find parameters. set_generic_shape_model_param (ModelHandle, 'num_matches', 1) set_generic_shape_model_param (ModelHandle, 'min_score', 0.5) find_generic_shape_model (ReferenceImage, ModelHandle, MatchResultID, Matches) get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', HomMat2DModel) * * Find the object in other images (online step). for i := 1 to 9 by 1 read_image (SearchImage, 'board/board_' + i$'02') find_generic_shape_model (SearchImage, ModelHandle, MatchResultID, Matches) get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', HomMat2DMatch) * Compute the transformation matrix. hom_mat2d_invert (HomMat2DMatch, HomMat2DMatchInvert) hom_mat2d_compose (HomMat2DModel, HomMat2DMatchInvert, TransformationMatrix) affine_trans_image (SearchImage, ImageAffineTrans, TransformationMatrix, 'constant', 'false') * * Visualization. dev_set_window (WindowHandle) dev_display (SearchImage) get_generic_shape_model_result_object (InstanceObject, MatchResultID, 'all', 'contours') dev_display (InstanceObject) * * Reading text and numbers on the aligned image. reduce_domain (ImageAffineTrans, ROIText, ImageOCR) find_text (ImageOCR, TextModel, TextResultID) get_text_object (Characters, TextResultID, 'all_lines') get_text_result (TextResultID, 'class', RecognizedText) * * Visualization. dev_set_window (WindowHandleText) dev_display (ImageAffineTrans) dev_set_colored (12) dev_display (Characters) disp_finding_text (Characters, WindowHandle, WindowHandleText, RecognizedText) wait_seconds (0.5) endfor disp_end_of_program_message (WindowHandle, 'black', 'true') stop () dev_close_window ()

解释如下代码:for pic_id1 in range(1,N_pic+1): print('matching ' + set_name +': ' +str(pic_id1).zfill(5)) N_CHANGE = 0 for T_id in range(1,16,3): for H_id in range(2,5): FAIL_CORNER = 0 data_mat1 = read_data(input_file,pic_id1,T_id,H_id) search_list = range( max((pic_id1-10),1),pic_id1)+ range(pic_id1+1, min((pic_id1 + 16),N_pic + 1 ) ) for cor_ind in range(0,N_cor): row_cent1 = cor_row_center[cor_ind] col_cent1 = cor_col_center[cor_ind] img_corner = data_mat1[(row_cent1-N_pad): (row_cent1+N_pad+1), (col_cent1-N_pad): (col_cent1+N_pad+1) ] if ((len(np.unique(img_corner))) >2)&(np.sum(img_corner ==1)< 0.8*(N_pad2+1)**2) : for pic_id2 in search_list: data_mat2 = read_data(input_file,pic_id2,T_id,H_id) match_result = cv2_based(data_mat2,img_corner) if len(match_result[0]) ==1: row_cent2 = match_result[0][0]+ N_pad col_cent2 = match_result[1][0]+ N_pad N_LEF = min( row_cent1 , row_cent2) N_TOP = min( col_cent1, col_cent2 ) N_RIG = min( L_img-1-row_cent1 , L_img-1-row_cent2) N_BOT = min( L_img-1-col_cent1 , L_img-1-col_cent2) IMG_CHECK1 = data_mat1[(row_cent1-N_LEF): (row_cent1+N_RIG+1), (col_cent1-N_TOP): (col_cent1+N_BOT+1) ] IMG_CHECK2 = data_mat2[(row_cent2-N_LEF): (row_cent2+N_RIG+1), (col_cent2-N_TOP): (col_cent2+N_BOT+1) ] if np.array_equal(IMG_CHECK1,IMG_CHECK2) : check_row_N = IMG_CHECK1.shape[0] check_col_N = IMG_CHECK1.shape[1] if (check_col_Ncheck_row_N>=25): match_all.append( (pic_id1, row_cent1, col_cent1, pic_id2 , row_cent2, col_cent2) ) search_list.remove(pic_id2) else: FAIL_CORNER = FAIL_CORNER +1 N_CHANGE = N_CHANGE + 1 #%% break if less than 1 useless corners, or have detected more than 10 images from 60 if(FAIL_CORNER <= 1): break

解释如下代码: for pic_id1 in range(1,N_pic+1): print('matching ' + set_name +': ' +str(pic_id1).zfill(5)) N_CHANGE = 0 for T_id in range(1,16,3): for H_id in range(2,5): FAIL_CORNER = 0 data_mat1 = read_data(input_file,pic_id1,T_id,H_id) search_list = range( max((pic_id1-10),1),pic_id1)+ range(pic_id1+1, min((pic_id1 + 16),N_pic + 1 ) ) for cor_ind in range(0,N_cor): row_cent1 = cor_row_center[cor_ind] col_cent1 = cor_col_center[cor_ind] img_corner = data_mat1[(row_cent1-N_pad): (row_cent1+N_pad+1), (col_cent1-N_pad): (col_cent1+N_pad+1) ] if ((len(np.unique(img_corner))) >2)&(np.sum(img_corner ==1)< 0.8*(N_pad2+1)**2) : for pic_id2 in search_list: data_mat2 = read_data(input_file,pic_id2,T_id,H_id) match_result = cv2_based(data_mat2,img_corner) if len(match_result[0]) ==1: row_cent2 = match_result[0][0]+ N_pad col_cent2 = match_result[1][0]+ N_pad N_LEF = min( row_cent1 , row_cent2) N_TOP = min( col_cent1, col_cent2 ) N_RIG = min( L_img-1-row_cent1 , L_img-1-row_cent2) N_BOT = min( L_img-1-col_cent1 , L_img-1-col_cent2) IMG_CHECK1 = data_mat1[(row_cent1-N_LEF): (row_cent1+N_RIG+1), (col_cent1-N_TOP): (col_cent1+N_BOT+1) ] IMG_CHECK2 = data_mat2[(row_cent2-N_LEF): (row_cent2+N_RIG+1), (col_cent2-N_TOP): (col_cent2+N_BOT+1) ] if np.array_equal(IMG_CHECK1,IMG_CHECK2) : check_row_N = IMG_CHECK1.shape[0] check_col_N = IMG_CHECK1.shape[1] if (check_col_Ncheck_row_N>=25): match_all.append( (pic_id1, row_cent1, col_cent1, pic_id2 , row_cent2, col_cent2) ) search_list.remove(pic_id2) else: FAIL_CORNER = FAIL_CORNER +1 N_CHANGE = N_CHANGE + 1 #%% break if less than 1 useless corners, or have detected more than 10 images from 60 if(FAIL_CORNER <= 1): break match_all_pd = pd.DataFrame(match_all,columns = ['pic_id1','row_id1','col_id1','pic_id2','row_id2','col_id2']) pd_add = pd.DataFrame(np.arange(1,N_pic+1), columns = ['pic_id1']) pd_add['pic_id2'] = pd_add['pic_id1'] pd_add['row_id1'] = 0 pd_add['row_id2'] = 0 pd_add['col_id1'] = 0 pd_add['col_id2'] = 0 match_all_pd = pd.concat([match_all_pd,pd_add]) match_all_pd.index = np.arange(len(match_all_pd))

最新推荐

recommend-type

open3d-0.11.2-cp36-cp36m-win_amd64.whl

open3d-0.11.2-cp36-cp36m-win_amd64.whl
recommend-type

SpringBoot是一个经典实用的员工管理系统。集成了Mybatis在MySQL数据库上的

SpringBoot是一个经典实用的员工管理系统。集成了Mybatis在MySQL数据库上的操作。页面模板使用themleaf。经典SpringBoot案例研究_ SpringBoot_案例研究_
recommend-type

nipy-0.4.1-cp35-cp35m-win_amd64.whl

nipy-0.4.1-cp35-cp35m-win_amd64.whl
recommend-type

算法部署-使用OpenVINO在FPGA上部署人脸检测算法-附详细流程教程+项目源码-优质项目实战.zip

算法部署_使用OpenVINO在FPGA上部署人脸检测算法_附详细流程教程+项目源码_优质项目实战
recommend-type

Pillow_SIMD-6.0.0.post0+avx2-cp35-cp35m-win_amd64.whl

Pillow_SIMD-6.0.0.post0+avx2-cp35-cp35m-win_amd64.whl
recommend-type

天池大数据比赛:伪造人脸图像检测技术

资源摘要信息:"天池大数据比赛伪造人脸攻击图像区分检测.zip文件包含了在天池大数据平台上举办的一场关于伪造人脸攻击图像区分检测比赛的相关资料。这个比赛主要关注的是如何通过技术手段检测和区分伪造的人脸攻击图像,即通常所说的“深度伪造”(deepfake)技术制作出的虚假图像。此类技术利用深度学习算法,特别是生成对抗网络(GANs),生成逼真的人物面部图像或者视频,这些伪造内容在娱乐领域之外的应用可能会导致诸如欺诈、操纵舆论、侵犯隐私等严重问题。 GANs是由两部分组成的系统:生成器(Generator)和判别器(Discriminator)。生成器产生新的数据实例,而判别器的目标是区分真实图像和生成器产生的图像。在训练过程中,生成器和判别器不断博弈,生成器努力制作越来越逼真的图像,而判别器则变得越来越擅长识别假图像。这个对抗过程最终使得生成器能够创造出与真实数据几乎无法区分的图像。 在检测伪造人脸图像方面,研究者和数据科学家们通常会使用机器学习和深度学习的多种算法。这些算法包括但不限于卷积神经网络(CNNs)、递归神经网络(RNNs)、自编码器、残差网络(ResNets)等。在实际应用中,研究人员可能会关注以下几个方面的特征来区分真假图像: 1. 图像质量:包括图像的分辨率、颜色分布、噪声水平等。 2. 人脸特征:例如眼睛、鼻子、嘴巴的位置和形状是否自然,以及与周围环境的融合度。 3. 不合逻辑的特征:例如眨眼频率、头部转动、面部表情等是否与真实人类行为一致。 4. 检测深度伪造特有的痕迹:如闪烁、帧间不一致等现象。 比赛的目的是为了鼓励开发者、数据科学家和研究者利用大数据和机器学习技术,提高对于深度伪造图像的检测精度。这种技术上的进步对于信息安全领域尤其重要,因为深度伪造技术正在变得越来越先进和难以检测。 资源包中的fakefacedetect-master文件可能是一个开源项目或框架,用于检测和区分伪造的人脸图像。这样的项目通常包括了数据集、训练好的模型、预测脚本以及评估方法等,方便参赛者快速开始项目并进行模型训练、测试和优化。在数据集方面,参与者可能会得到包含真实与伪造人脸图像的大量数据用于训练和验证模型。此外,为了确保比赛的公平性和可复现性,项目可能还包括了详细的说明文档和评价标准。" 结束语:由于本次回答的约束,以上内容为根据提供的信息所总结的知识点,实际内容的详细程度和准确性需要进一步的资源验证。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【Go测试框架端到端测试】:构建与优化集成测试流程

![【Go测试框架端到端测试】:构建与优化集成测试流程](https://higherlogicdownload.s3.amazonaws.com/IMWUC/UploadedImages/BwMBmIrURV2rHRunpVBX_ut-and-ct-3.png) # 1. Go测试框架的基本概念 在软件开发领域,测试是一项至关重要的工作,它确保软件的质量和稳定性。Go语言作为一门现代编程语言,提供了一套完善的测试框架,使得测试工作变得高效而系统。 Go的测试框架是基于其独特的包系统构建的,能够自动识别所有以`_test.go`结尾的文件,并将这些文件视为测试代码。该框架支持三大类测试:
recommend-type

不使用temp怎么改写该程序

在不使用额外临时变量的情况下,使用`switch`语句并结合三元运算符来查找并交换数组中的最小、第二小和第三小的元素可能会比较复杂。这种实现通常适用于特定条件下的小型数据集,而不是通用的排序算法。以下是例子: ```c #include <stdio.h> void find_and_replace(int a[], int n) { int min, second_min, third_min; int i; for (i = 0; i < n; ++i) { min = a[0]; second_min = a[0];
recommend-type

ADS1118数据手册中英文版合集

资源摘要信息:"ADS1118中文资料和英文资料.zip" ADS1118是一款由德州仪器(Texas Instruments,简称TI)制造的高精度16位模拟到数字转换器(Analog-to-Digital Converter,ADC)。ADS1118拥有一个可编程增益放大器(Programmable Gain Amplifier,PGA),能够在不同的采样率和分辨率下进行转换。此ADC特别适用于那些需要精确和低噪声信号测量的应用,如便携式医疗设备、工业传感器以及测试和测量设备。 ADS1118的主要特点包括: - 高精度:16位无噪声分辨率。 - 可编程增益放大器:支持多种增益设置,从±2/3到±16 V/V,用于优化信号动态范围。 - 多种数据速率:在不同的采样率(最高860 SPS)下提供精确的数据转换。 - 多功能输入:可进行单端或差分输入测量,差分测量有助于提高测量精度并抑制共模噪声。 - 内部参考电压:带有1.25V的内部参考电压,方便省去外部参考源。 - 低功耗设计:非常适合电池供电的应用,因为它能够在待机模式下保持低功耗。 - I2C接口:提供一个简单的串行接口,方便与其他微处理器或微控制器通信。 该设备通常用于需要高精度测量和低噪声性能的应用中。例如,在医疗设备中,ADS1118可用于精确测量生物电信号,如心电图(ECG)信号。在工业领域,它可以用于测量温度、压力或重量等传感器的输出。此外,ADS1118还可以在实验室设备中找到,用于高精度的数据采集任务。 TI-ADS1118.pdf和ADS1118IDGSR_中文资料.PDF文件是德州仪器提供的ADS1118设备的官方文档。这些文件通常包含了该芯片的详细技术规格、操作方法、应用指导和封装信息等。中文资料版本是为了方便中文使用者更好地理解和应用ADS1118产品。英文资料版本则为非中文地区的工程师或技术人员提供技术信息。 在这些资料中,用户可以找到包括但不限于以下内容: - 引脚分配和封装说明:为设计者提供芯片布局和封装的详细信息。 - 功能框图:帮助理解ADS1118的内部结构和信号流程。 - 引脚描述:介绍每个引脚的功能和要求。 - 电气特性:包括直流和交流参数,如电源电压、输入电压范围、输出驱动能力等。 - 应用电路:提供设计示例和参考,帮助用户实现高性能的数据采集系统。 - 时序图:详细说明了I2C通信协议下的时序要求,为编程提供精确参考。 - 设计建议:根据德州仪器的工程师经验,提供改善设计性能和稳定性的建议。 - 机械图:展示了芯片的物理尺寸和引脚间距,帮助设计印刷电路板(PCB)。 ADS1118因其高性能和易用性,在众多精密测量应用中得到了广泛的应用。通过阅读这些资料,开发者可以充分利用ADS1118的功能,实现高质量的数据采集和处理。