Get Intensity along a line based on OpenCV
The interpolate function is used to get intensity of a point which is not on exactly a pixel.
The code is written in C++. Because it is template function, so they should be put in header file.
// Interpolates pixel intensity with subpixel accuracy.
// Abount bilinear interpolation in Wikipedia:
// http://en.wikipedia.org/wiki/Bilinear_interpolation
template <class T>
float interpolate(const Mat &mat, float x, float y)
{
// Get the nearest integer pixel coords (xi;yi).
int xi = cvFloor(x);
int yi = cvFloor(y); float k1 = x - xi; // Coefficients for interpolation formula.
float k2 = y - yi; bool b1 = xi < mat.cols - 1; // Check that pixels to the right
bool b2 = yi < mat.rows - 1; // and to down direction exist. float UL = mat.at<T>(Point(xi, yi));
float UR = b1 ? mat.at<T>( Point (xi + 1, yi ) ) : 0.f;
float LL = b2 ? mat.at<T>( Point ( xi, yi + 1) ) : 0.f;
float LR = b1 & b2 ? mat.at <T>( Point ( xi + 1, yi + 1 ) ) : 0.f; // Interpolate pixel intensity.
float interpolated_value = (1.0f - k1) * (1.0f - k2) * UL + k1 * (1.0f - k2) * UR +
(1.0f - k1) * k2 * LL + k1 * k2 * LR; return interpolated_value;
} //Get the intensity along an input line
template <class T>
int GetIntensityOnLine ( const Mat &mat, const Point &start, const Point &end, vector<float> &vecOutput )
{
if ( start.x >= mat.cols || start.y >= mat.rows )
return -1;
if ( end.x >= mat.cols || end.y >= mat.rows )
return -1; float fLineLen = (float)sqrt ( ( end.x - start.x ) * ( end.x - start.x ) + ( end.y - start.y ) * ( end.y - start.y ) );
if ( fLineLen < 1 )
return -1; float fCos = ( end.x - start.x ) / fLineLen;
float fSin = ( end.y - start.y ) / fLineLen; float fCurrentLen = 0.f;
while ( fCurrentLen < fLineLen ) {
float fX = start.x + fCos * fCurrentLen;
float fY = start.y + fSin * fCurrentLen;
float fIntensity = interpolate<T> ( mat, fX, fY );
vecOutput.push_back ( fIntensity ); ++ fCurrentLen;
} return 0;
}
Get Intensity along a line based on OpenCV的更多相关文章
- logoff remote desktop sessions via command line tools
This trick I learned from my one of ex-college. In Windows servers, only two remote desktop session ...
- Build OpenCV text(OCR) module on windows
Background. AOI software needs to use the OCR feature to recognize the texts on the chips. Because o ...
- OpenCV Template Matching Subpixel Accuracy
OpenCV has function matchTemplate to easily do the template matching. But its accuracy can only reac ...
- OpenCV CommandLineParser 的用法
OpenCV CommandLineParser 的用法 去百度了一下,关键字:OpenCV CommandLineParser 发现,最多的讲解是:opencv源码解析之(5):CommandLi ...
- Android OpenCV实现图片叠加,水印
关于如何用纯OpenCV实现图片叠加的例子实在是太少,太多的是使用 C++,JNI实现的,如果要用C++的话,我们为啥不转行做C++ 下面的例子基于 Android JavaCV 实现了在im_bea ...
- 基于OpenCV的面部交换
需要装python库 OpenCV dlib docopt(根据打开方式选择是否装) # -*- coding: UTF-8 #本电脑试运行 命令 python F:\python_project\s ...
- opencv霍夫变换
霍夫变换不仅可以找出图片中的直线,也可以找出圆,椭圆,三角形等等,只要你能定义出直线方程,圆形的方程等等. 不得不说,现在网上的各种博客质量真的不行,网上一堆文章,乱TM瞎写,误人子弟.本身自己就没有 ...
- opencv之霍夫曼变换
霍夫变换不仅可以找出图片中的直线,也可以找出圆,椭圆,三角形等等,只要你能定义出直线方程,圆形的方程等等. 不得不说,现在网上的各种博客质量真的不行,网上一堆文章,乱TM瞎写,误人子弟.本身自己就没有 ...
- 行为识别(action recognition)相关资料
转自:http://blog.csdn.net/kezunhai/article/details/50176209 ================华丽分割线=================这部分来 ...
随机推荐
- Hadoop学习笔记
今天开始要学习Hadoop!开始向"大数据"领域靠拢! 从头开始对于连何为Hadoop都不清楚的人,有好多东西要学,加油! 1.下载hadoop,官网地址:http://mirro ...
- mysql主从复制+读写分离 菜鸟入门
MYsql主从复制 1.mysql主从复制原理: Master将数据变化记录到二进制日志中[binary log] Slave将master的二进制日志[binary log]拷贝到自己的中继日志[r ...
- 阿里云的9折推荐码 8DIER4
推荐码: 8DIER4 我有一个阿里云9折推荐码:8DIER4,分享给你,第一次购买云服务器或云数据库可享受原价9折优惠,还可多人使用,拿走不谢. 阿里云地址:http://www.aliyun.co ...
- 解决“动软代码生成器在SqlServer中会将唯一索引识别为主键"的Bug
动软代码生成器在SqlServer中,生成的代码会将唯一索引错误地识别为主键, 反编译源代码后,发现其中的SQL条件有误,现修复此Bug. 修复方法:将附件中的”Maticsoft.DbObjects ...
- AngularJS---表达式
AngularJS的表达式是放在{{}}里面,用{{ }}符号将一个变量绑定到$scope上. angularJS中的表达式有如下特点: 1.只能在其所属作用域内部 所有的表达式都在其所属的作用域内部 ...
- maven笔记
jar间接依赖: 被依赖的jar的范围要设置成compile,因发布会包含test范围依赖的jar包. 建立项目之间的联系:先在pom中设定依赖关系,然后可以引用了 .conf: C ...
- IQueryable,IEnumerable,List相互转换
发个文记录一下犯的错误吧!!! 如果在使用ASP.NET MVC很多的数据存取都是以IQueryable<>泛型类接收,那么在做两个IQueryable<>集合拼接时对于新手可 ...
- .net网站发布到局域网流程
将.net网站发布到局域网的服务器上,会遇到一些版本问题,下面把发布的流程简单说一下 一:发布网站 1.首先把需要的引用程序集都重新生成一下 2.程序集都重新生成之后,右击网站项目,选择发布选项 3. ...
- viewPager--viewpager时,发生内存溢出OOM问题
两个问题:1.如果图片达到500kb每张,你这个划屏会有顿卡:2.快速滑动有出现0.几秒的白屏.图片越大,顿卡越明显. 回复parcool:500kb的背景算大的了,如果是想做图片墙,viewpage ...
- Nexus3.0.0+Maven的使用(三)
这章主要讲怎么和Maven做集成,集成的方式主要分以下种情况:代理中央仓库.Snapshot包的管理.Release包的管理.第三方Jar上传到Nexus上 1 代理中央仓库 只要在PMO文件中配置 ...