博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用nodeitk进行对象识别
阅读量:5253 次
发布时间:2019-06-14

本文共 3102 字,大约阅读时间需要 10 分钟。

前言

东莞,晴,29至27度。忙了一天,最终能够写写东西了。今天继续昨天的话题,我们在昨天的例了基础上完好,通过匹配关键点求出映射从而找到场景中的已知对象。

目标

本文你将学习

  1. 採用nodeitk的findHomography和perspectiveTransform进行对象识别。
  2. 此外,样例基本包括nodeitk的一些基本数据结构的使用:NodeOpenCVMat, NodeOpenCVKeyPoint, NodeOpenCVPoint
  3. 上述主要的数据结构在nodeitk版本号稳定后将会在使用手冊中说明
代码

var node_itk = require('./node-itk');var img_object = node_itk.cv.imread( "./images/box.png", node_itk.cv.CV_LOAD_IMAGE_GRAYSCALE );var img_scene = node_itk.cv.imread( "./images/box_in_scene.png", node_itk.cv.CV_LOAD_IMAGE_GRAYSCALE );minHessian = 400detector = new node_itk.cv.NodeOpenCVFeatureDetector("SURF")detector.Set("hessianThreshold", minHessian)keypoints_object = detector.Detect( img_object );keypoints_scene = detector.Detect( img_scene );extractor = new node_itk.cv.NodeOpenCVDescriptorExtractor("SURF");descriptors_object = extractor.Compute(img_object, keypoints_object)descriptors_scene = extractor.Compute(img_scene, keypoints_scene)matcher = new node_itk.cv.NodeOpenCVDescriptorMatcher("FlannBased");matches = matcher.Match(descriptors_object, descriptors_scene);max_dist=0min_dist=100for (var i = 0; i < descriptors_object.Rows(); i++ ) {	dist = matches[i].GetDistance();	if (dist < min_dist) min_dist = dist;	if (dist > max_dist) max_dist = dist;};console.log("-- Max dist : " + max_dist + "\n")console.log("-- Min dist : " + min_dist + "\n")var good_matches = [];for( var i = 0; i < descriptors_object.Rows(); i++ ){ 	if( matches[i].GetDistance() <= 3*min_dist )	{ good_matches.push( matches[i] ); }}img_matches = node_itk.cv.DrawMatches(img_object, keypoints_object, img_scene, keypoints_scene, good_matches);var obj=[], scene=[];for (var i = 0; i < good_matches.length; i++) {	obj.push( keypoints_object[good_matches[i].GetQueryIdx()].PT() )	scene.push( keypoints_scene[good_matches[i].GetTrainIdx()].PT() )};H = node_itk.cv.FindHomography( obj, scene, node_itk.cv.CV_RANSAC );obj_corners = []obj_corners[0] = new node_itk.cv.NodeOpenCVPoint("Point2d", [0,0])obj_corners[1] = new node_itk.cv.NodeOpenCVPoint("Point2d", [img_object.Cols(),0])obj_corners[2] = new node_itk.cv.NodeOpenCVPoint("Point2d", [img_object.Cols(),img_object.Rows()])obj_corners[3] = new node_itk.cv.NodeOpenCVPoint("Point2d", [0,img_object.Rows()])tmp = new node_itk.cv.NodeOpenCVPoint("Point2d", [img_object.Cols(),0]);color = new node_itk.cv.NodeOpenCVScalar("Scalar", [0,255,0]);scene_corners = node_itk.cv.PerspectiveTransform(obj_corners, H.res);node_itk.cv.Line(img_matches, scene_corners[0].Add(tmp), scene_corners[1].Add(tmp), color, 2)node_itk.cv.Line(img_matches, scene_corners[1].Add(tmp), scene_corners[2].Add(tmp), color, 2)node_itk.cv.Line(img_matches, scene_corners[2].Add(tmp), scene_corners[3].Add(tmp), color, 2)node_itk.cv.Line(img_matches, scene_corners[3].Add(tmp), scene_corners[0].Add(tmp), color, 2)node_itk.cv.NamedWindow( "Good Matches & Object detection", node_itk.cv.CV_WINDOW_AUTOSIZE );node_itk.cv.imshow( "Good Matches & Object detection", img_matches );node_itk.cv.WaitKey ( 0 );

结果

小结

本文是昨天话题的深化,代码依旧比較简洁。这是nodeitk遵循的原则:以简单的方式高速实现图像处理应用。喜欢的朋友就点踩,想说点东西的就评论吧!^_^ 待续

转载于:https://www.cnblogs.com/mfrbuaa/p/4173230.html

你可能感兴趣的文章
HDU - 3949 线性基应用
查看>>
CodeChef - RIN 最小割应用 规划问题
查看>>
设计模式之组合模式
查看>>
百度分享如何自定义分享url和内容?
查看>>
php抓取post方式提交的页面
查看>>
php简单缓存类
查看>>
文件中查找
查看>>
20145313张雪纯网络攻防第二次实验
查看>>
人人网JavaScript面试题
查看>>
Kontln的属性形式Getter和Setter
查看>>
win10 bcdedit加入vhdx启动
查看>>
Linux 黑白界面显示
查看>>
ActiveMQ学习系列(四)----消息持久化到mysql
查看>>
JavaScript设计模式基础之面向对象的JavaScript(一)
查看>>
RabbitMQ-从基础到实战(4)— 消息的交换(中)
查看>>
mysql 索引数据结构及原理
查看>>
01.Hibernate入门
查看>>
Ubuntu 16.0.4开启 log-bin
查看>>
mongoDB的学习【小白的福音】
查看>>
软件工程的实践项目的自我目标
查看>>