opencv基本操作(三)
来源:互联网 发布:mysql saas 编辑:程序博客网 时间:2024/04/19 23:27
经常要遍历整个矩阵,还是写个工具链来辅助访问吧
#ifndef LINESITERATOR_HPP_0x000001#define LINESITERATOR_HPP_0x000001#include <cplusplus_basic.hpp>namespace _pns_private {namespace _pns_opencv_utility {template<bool> class BasicLinesIterator;template<>class BasicLinesIterator<false> {protected: typedef unsigned char *_p_data_t; typedef int _p_int_t; _p_data_t _mp_begin_pointer; _p_data_t _mp_current_pointer; _p_data_t _mp_end_pointer; _p_int_t _mp_step;public: typedef float float32_type; typedef double float64_type; static_assert(sizeof(float64_type)==8,""); static_assert(sizeof(float32_type)==4,""); BasicLinesIterator(): _mp_begin_pointer(nullptr), _mp_current_pointer(nullptr), _mp_end_pointer(nullptr), _mp_step(0){} BasicLinesIterator( const _p_data_t begin_arg, _p_int_t line_size_arg, _p_int_t step_arg): _mp_begin_pointer(const_cast<_p_data_t>(begin_arg)), _mp_current_pointer(const_cast<_p_data_t>(begin_arg)), _mp_end_pointer(const_cast<_p_data_t>(begin_arg) +(line_size_arg*step_arg)), _mp_step(step_arg) { } void goNext() { _mp_current_pointer+=_mp_step; } void goPrevious() { _mp_current_pointer-=_mp_step; } void goNext(_p_int_t arg) { _mp_current_pointer+=_mp_step*arg; } void goPrevious(_p_int_t arg) { _mp_current_pointer-=_mp_step*arg; } void goFirst() { _mp_current_pointer=_mp_begin_pointer; } void goLast() { _mp_current_pointer=_mp_end_pointer; }};template<>class BasicLinesIterator<true> :public BasicLinesIterator<false> { using _Super=BasicLinesIterator<false>;protected: _p_int_t _mp_current_line; _p_int_t _mp_lines_count;public: BasicLinesIterator(): _mp_current_line(0), _mp_lines_count(0){} BasicLinesIterator(const _p_data_t begin_arg, _p_int_t line_size_arg, _p_int_t step_arg): _Super(begin_arg,line_size_arg,step_arg), _mp_current_line(0), _mp_lines_count(line_size_arg) { } _p_int_t lineCount() const { return this->_mp_lines_count; } _p_int_t currentLineNumber() const { return this->_mp_current_line; } void goNext() { _mp_current_pointer+=_mp_step; ++_mp_current_line; } void goPrevious() { _mp_current_pointer-=_mp_step; --_mp_current_line; } void goNext(_p_int_t arg) { _mp_current_pointer+=_mp_step*arg; _mp_current_line+=arg; } void goPrevious(_p_int_t arg) { _mp_current_pointer-=_mp_step*arg; _mp_current_line-=arg; } void goFirst() { _mp_current_pointer=_mp_begin_pointer; _mp_current_line=0; } void goLast() { _mp_current_pointer=_mp_end_pointer; _mp_current_line=_mp_lines_count; }};template<bool _HasLineNumber_=false>class LinesIterator : public BasicLinesIterator<_HasLineNumber_> { using _Super=BasicLinesIterator<_HasLineNumber_>; using typename _Super::_p_data_t; using typename _Super::_p_int_t;public: LinesIterator()=default; LinesIterator(const _p_data_t begin_arg, _p_int_t line_size_arg, _p_int_t step_arg) :_Super(begin_arg,line_size_arg,step_arg) { } _p_int_t step()const { return this->_mp_step; } template<typename _T_> _T_ * firstLine() { return reinterpret_cast<_T_ *>(this->_mp_begin_pointer); } template<typename _T_> const _T_ * firstLine()const { return reinterpret_cast<const _T_ *>(this->_mp_begin_pointer); } template<typename _T_> _T_ * lastLine() { return reinterpret_cast<_T_ *>(this->_mp_end_pointer); } template<typename _T_> const _T_ * lastLine()const { return reinterpret_cast<const _T_ *>(this->_mp_end_pointer); } template<typename _T_> _T_* currentLine() { return reinterpret_cast<_T_*>(this->_mp_current_pointer); } template<typename _T_> const _T_* currentLine() const { return reinterpret_cast<const _T_*>(this->_mp_current_pointer); } template<typename _T_> _T_* nextLine() { return reinterpret_cast<_T_*>(this->_mp_current_pointer+this->_mp_step); } template<typename _T_> const _T_* nextLine()const { return reinterpret_cast<const _T_*>(this->_mp_current_pointer+this->_mp_step); } template<typename _T_> _T_* previousLine() { return reinterpret_cast<_T_*>(this->_mp_current_pointer-this->_mp_step); } template<typename _T_> const _T_* previousLine()const { return reinterpret_cast<const _T_*>(this->_mp_current_pointer-this->_mp_step); } template<typename _T_> _T_* nextLine(_p_int_t arg) { return reinterpret_cast<_T_*>(this->_mp_current_pointer+arg*this->_mp_step); } template<typename _T_> const _T_* nextLine(_p_int_t arg)const { return reinterpret_cast<const _T_*>(this->_mp_current_pointer+arg*this->_mp_step); } template<typename _T_> _T_* previousLine(_p_int_t arg) { return reinterpret_cast<_T_*>(this->_mp_current_pointer-arg*this->_mp_step); } template<typename _T_> const _T_* previousLine(int arg)const { return reinterpret_cast<const _T_*>(this->_mp_current_pointer-arg*this->_mp_step); } bool isFinePointer(const void *arg) const { return (arg<static_cast<const void *>(this->_mp_end_pointer))&& (static_cast<const void*>(this->_mp_begin_pointer)<=arg); } operator bool() const { return this->_mp_current_pointer<this->_mp_end_pointer; } bool isFinePointer() const { return (this->_mp_current_pointer<this->_mp_end_pointer)&& (this->_mp_begin_pointer<=this->_mp_current_pointer); }private: CPLUSPLUS_OBJECT(LinesIterator)};extern template class LinesIterator<true>;extern template class LinesIterator<false>;}/*_pns_opencv_utility*/}/*_pns_private*/using _pns_private::_pns_opencv_utility::LinesIterator;#endif // LINESITERATOR_HPP
0 0
- opencv基本操作(三)
- Opencv学习笔记(三)--图像处理的基本操作
- 从零开始 OpenCV (三) —— 矩阵/图像的基本操作
- OpenCV基本操作
- opencv基本操作
- opencv基本图像操作
- opencv基本操作
- OpenCV基本操作
- opencv Mat基本操作
- Opencv基本操作
- OpenCV基本操作学习
- opencv图像基本操作
- OpenCV | 基本操作API
- opencv基本操作(二)
- opencv基本操作四
- opencv基本操作(五)
- opencv基本操作(六)
- openCV矩阵基本操作
- 自旋锁
- Abbott的复仇(Abbott's Revenge)BFS算法实现
- 大数阶乘...
- 全面介绍Android Studio中Git的使用(一)
- 全面介绍Android Studio中Git 的使用(二)
- opencv基本操作(三)
- 趣味程序 - 块状文件数据存储
- QuickBMS解包使用指南
- 创建一个数据库userdb,该库中有一个名为user的表,该表用于存放注册用户的信息,user ( id char(18) not null primary key, psd char(16))。 完
- 【C#】——扩展方法
- shell语法 简单回记导图
- webservice开发一:webservice基本概念
- Swift 3.0中UITableViewCell纯代码自定义
- [Android]:Android studio 添加jar后编译报错