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 ================华丽分割线=================这部分来 ...
随机推荐
- Android应用开发-数据存储和界面展现(二)(重制版)
SQLite数据库 // 自定义类MyOpenHelper继承自SQLiteOpenHelper MyOpenHelper oh = new MyOpenHelper(getContext(), &q ...
- sp_who_lock
USE MyDataBase GO /****** Object: StoredProcedure [dbo].[sp_who_lock] Script Date: 4/10/2015 ******/ ...
- AJAX-创建XMLHttpRequest对象
AJAX-创建XMLHttpRequest对象 1.XMLHttpRequest是AJAX的基础,所有现在浏览器都支持,用于在后台与服务器交换数据,也就意味着可以在不加载整个页面的情况下对整个页面进 ...
- 从数据库中导出excel报表
通常需要将后台数据库中的数据集或者是其他列表等导出excel 报表,这里主要引用了Apose.cells dll 类库, (1)直接上主要代码: protected void txtExport_Cl ...
- Oracle 11g 密码永不过期设置
[原因/触发因素] 确定是由于oracle11g中默认在default概要文件中设置了“PASSWORD_LIFE_TIME=180天”所导致. [影响和风险] 影响 密码过期后,业务进程连接数据库异 ...
- OAF_开发系列04_实现OAF查询4种不同的实现方式的比较和实现(案例)
2014-06-02 Created By BaoXinjian
- Codeforces Round #377 (Div. 2) D. Exams(二分答案)
D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...
- Ubuntu16.10 主题flatabulous安装
以前通过apt直接安装的flatabulous主题16.10上安装会出现找不到包的情况,可以采用源码安装 原来的apt-get方式: 1:主题 sudo add-apt-repository ppa: ...
- 【解决】SharePoint 2013 with SP1安装问题及解决
安装环境 操作系统:Windows Server 2008 R2 SP1 安装包:SharePoint Server 2013 with SP1 问题及解决 I. 必备组件(prerequisitei ...
- 文本XSS攻击过滤
在FCK或百度编辑器等常用富文本编辑器中,通常是会被XSS攻击 处理方法: 文本框模拟输入了以下文本 <span style="dispaly:none" onclick=& ...