打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
cvBlob windows7 安装说明

-----------------------------------------cvblob 介绍 -----------------------------------------------

计算机视觉的一个库。用来检测二进制数字图像中的连通区域。

效果如下图:

官网关于编译,安装,如何使用的解释都不够细致。作为小白极其容易失误。

所以我在这里按照我自己的成功过程来介绍。

FAQ里包含四部分问题  -- 介绍, 编译,使用这个库,杂记

http://code.google.com/p/cvblob/wiki/FAQ 但是也是不够细致

总体而言我觉得cvblob就是一个小众的库 但是我用着感觉效果还蛮不错的 

--------------------------------------cvblob下载与安装-------------------------------------------

cvblob 官网  http://code.google.com/p/cvblob/

1. 下载库0.10.4
2. 安装opencv2.4.3
3. 安装cmake 2.8.12

4设置cvblob中文件CMakeLists.txt文件

即E:\cvblob\cvBlob\CMakeLists.txt文件中,在find_package(OpenCV REQUIRED) 这条语句下加入:

  1. set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeScripts)  
  2. set(OpenCV_DIR E:\OpenCV2.4.3\opencv\build)  
最终该文件非注释语句内容如下:

  1. find_package(OpenCV REQUIRED)  
  2. set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeScripts)  
  3. set(OpenCV_DIR E:\OpenCV2.4.3\opencv\build)  
  4. set(cvBlob_CVBLOB cvblob.cpp  
  5.                    cvlabel.cpp  
  6.            cvaux.cpp  
  7.            cvcontour.cpp  
  8.                    cvtrack.cpp  
  9.            cvcolor.cpp  
  10. )  
  11.   
  12. set_source_files_properties(${cvBlob_SRC}  
  13.                             PROPERTIES  
  14.                             COMPILE_FLAGS "-O3"  
  15. )  
  16.   
  17. add_library(cvblob SHARED ${cvBlob_CVBLOB})  
  18.   
  19. target_link_libraries(cvblob ${OpenCV_LIBS})  
  20.   
  21. install(FILES cvblob.h DESTINATION include)  
  22.   
  23. install(TARGETS cvblob  
  24.         RUNTIME DESTINATION bin  
  25.         LIBRARY DESTINATION lib  
  26.         ARCHIVE DESTINATION lib  
  27. )  


5. 编译 (cmake) opencv2.4.3 源码:


 头一次用需要选择编译器 默认用vs2010 就好啦  

1.填写:where is the source code和where to build the binaries 


2. 点击:configure

3. 点击: Generate

注: 在生成configure和generate的结果过程中,关键是中间没有任何红色的错误显示。如果有错误会以红色来显示,自行处理,有些是因为自己电脑没有配置譬如TBB等等,如果没有就把勾去掉就好啦。

以下截图是我都已经弄好所有的配置之后的截图: 

1.config前:

configure done:

generate done:


5.5 在vs2010中运行OpenCV cmake项目:

打开E:\OpenCV2.4.3\cmake 文件夹中的opencv.sln。分别在debug和release模式下运行opencv项目。(介个应该不用解释吧?)


6. 用cmake软件编译(cmake)cvblob   源码: -- 我把cvblob 编译的结果文件夹命名为cvblob_cmake就是where to build the binaries要填写的就是cmake的根目录
其他步骤同上。最终generate成功cvblob_cmake这个vs2010的项目。

以下图像是我已经处理好所有的配置之后的截图:

设置好两个where路径:


configure done:


generation done:


  7. 打开cvblob_cmake中生成 vs2010项目(嗯,对就是点击E:\cvblob_cmake目录下的cvBlob.sln)

找到cvblob.h文件

--a. 在其中添加:#define EXPORT __declspec (dllexport)

--b. 在extern "C"块中 每个函数前都添加EXPORT关键字

代码如下: 灰常长。。。我不知道怎么才能折叠。。。

  1. // Copyright (C) 2007 by Cristóbal Carnero Li?án  
  2. // grendel.ccl@gmail.com  
  3. //  
  4. // This file is part of cvBlob.  
  5. //  
  6. // cvBlob is free software: you can redistribute it and/or modify  
  7. // it under the terms of the Lesser GNU General Public License as published by  
  8. // the Free Software Foundation, either version 3 of the License, or  
  9. // (at your option) any later version.  
  10. //  
  11. // cvBlob is distributed in the hope that it will be useful,  
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of  
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
  14. // Lesser GNU General Public License for more details.  
  15. //  
  16. // You should have received a copy of the Lesser GNU General Public License  
  17. // along with cvBlob.  If not, see <http://www.gnu.org/licenses/>.  
  18. //  
  19.   
  20. /// \file cvblob.h  
  21. /// \brief OpenCV Blob header file.  
  22.   
  23. #define EXPORT __declspec (dllexport)  
  24.   
  25. #ifdef SWIG  
  26. %module cvblob  
  27. %{  
  28. #include "cvblob.h"  
  29. %}  
  30. #endif  
  31.   
  32. #ifndef CVBLOB_H  
  33. #define CVBLOB_H  
  34.   
  35. #include <iostream>  
  36. #include <map>  
  37. #include <list>  
  38. #include <vector>  
  39. #include <limits>  
  40.   
  41. #if (defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) || (defined(__APPLE__) & defined(__MACH__)))  
  42. #include <cv.h>  
  43. #else  
  44. #include <opencv/cv.h>  
  45. #endif  
  46.   
  47. #ifndef __CV_BEGIN__  
  48. #define __CV_BEGIN__ __BEGIN__  
  49. #endif  
  50. #ifndef __CV_END__  
  51. #define __CV_END__ __END__  
  52. #endif  
  53.   
  54. #ifdef __cplusplus  
  55. extern "C" {  
  56. #endif  
  57.   
  58.   namespace cvb  
  59.   {  
  60.   
  61.   ////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  62.   // Contours  
  63.   
  64.   // Chain code:  
  65.   //        7 0 1  
  66.   //        6   2  
  67.   //        5 4 3  
  68. #define CV_CHAINCODE_UP     0 ///< Up.  
  69. #define CV_CHAINCODE_UP_RIGHT   1 ///< Up and right.  
  70. #define CV_CHAINCODE_RIGHT  2 ///< Right.  
  71. #define CV_CHAINCODE_DOWN_RIGHT 3 ///< Down and right.  
  72. #define CV_CHAINCODE_DOWN   4 ///< Down.  
  73. #define CV_CHAINCODE_DOWN_LEFT  5 ///< Down and left.  
  74. #define CV_CHAINCODE_LEFT   6 ///< Left.  
  75. #define CV_CHAINCODE_UP_LEFT    7 ///< Up and left.  
  76.   
  77.   /// \brief Move vectors of chain codes.  
  78.   /// \see CV_CHAINCODE_UP  
  79.   /// \see CV_CHAINCODE_UP_LEFT  
  80.   /// \see CV_CHAINCODE_LEFT  
  81.   /// \see CV_CHAINCODE_DOWN_LEFT  
  82.   /// \see CV_CHAINCODE_DOWN  
  83.   /// \see CV_CHAINCODE_DOWN_RIGHT  
  84.   /// \see CV_CHAINCODE_RIGHT  
  85.   /// \see CV_CHAINCODE_UP_RIGHT  
  86.   const char cvChainCodeMoves[8][2] = { { 0, -1},  
  87.                                         { 1, -1},  
  88.                     { 1,  0},  
  89.                     { 1,  1},  
  90.                     { 0,  1},  
  91.                     {-1,  1},  
  92.                     {-1,  0},  
  93.                     {-1, -1}  
  94.                                       };  
  95.   
  96.   /// \brief Direction.  
  97.   /// \see CV_CHAINCODE_UP  
  98.   /// \see CV_CHAINCODE_UP_LEFT  
  99.   /// \see CV_CHAINCODE_LEFT  
  100.   /// \see CV_CHAINCODE_DOWN_LEFT  
  101.   /// \see CV_CHAINCODE_DOWN  
  102.   /// \see CV_CHAINCODE_DOWN_RIGHT  
  103.   /// \see CV_CHAINCODE_RIGHT  
  104.   /// \see CV_CHAINCODE_UP_RIGHT  
  105.   typedef unsigned char CvChainCode;  
  106.   
  107.   /// \brief Chain code.  
  108.   /// \see CvChainCode  
  109.   typedef std::list<CvChainCode> CvChainCodes;  
  110.   
  111.   /// \brief Chain code contour.  
  112.   /// \see CvChainCodes  
  113.   struct CvContourChainCode  
  114.   {  
  115.     CvPoint startingPoint; ///< Point where contour begin.  
  116.     CvChainCodes chainCode; ///< Polygon description based on chain codes.  
  117.   };  
  118.   
  119.   typedef std::list<CvContourChainCode *> CvContoursChainCode; ///< List of contours (chain codes type).  
  120.   
  121.   /// \brief Polygon based contour.  
  122.   typedef std::vector<CvPoint> CvContourPolygon;  
  123.   
  124.   /// \fn void cvRenderContourChainCode(CvContourChainCode const *contour, IplImage const *img, CvScalar const &color=CV_RGB(255, 255, 255))  
  125.   /// \brief Draw a contour.  
  126.   /// \param contour Chain code contour.  
  127.   /// \param img Image to draw on.  
  128.   /// \param color Color to draw (default, white).  
  129.   /// \see CvContourChainCode  
  130.   EXPORT void cvRenderContourChainCode(CvContourChainCode const *contour, IplImage const *img, CvScalar const &color=CV_RGB(255, 255, 255));  
  131.     
  132.   /// \fn CvContourPolygon *cvConvertChainCodesToPolygon(CvContourChainCode const *cc)  
  133.   /// \brief Convert a chain code contour to a polygon.  
  134.   /// \param cc Chain code contour.  
  135.   /// \return A polygon.  
  136.   /// \see CvContourChainCode  
  137.   /// \see CvContourPolygon  
  138.   EXPORT CvContourPolygon *cvConvertChainCodesToPolygon(CvContourChainCode const *cc);  
  139.   
  140.   /// \fn void cvRenderContourPolygon(CvContourPolygon const *contour, IplImage *img, CvScalar const &color=CV_RGB(255, 255, 255))  
  141.   /// \brief Draw a polygon.  
  142.   /// \param contour Polygon contour.  
  143.   /// \param img Image to draw on.  
  144.   /// \param color Color to draw (default, white).  
  145.   /// \see CvContourPolygon  
  146.   EXPORT void cvRenderContourPolygon(CvContourPolygon const *contour, IplImage *img, CvScalar const &color=CV_RGB(255, 255, 255));  
  147.   
  148.   /// \fn double cvContourPolygonArea(CvContourPolygon const *p)  
  149.   /// \brief Calculates area of a polygonal contour.  
  150.   /// \param p Contour (polygon type).  
  151.   /// \return Area of the contour.  
  152.  EXPORT double cvContourPolygonArea(CvContourPolygon const *p);  
  153.   
  154.   /// \fn double cvContourChainCodePerimeter(CvContourChainCode const *c)  
  155.   /// \brief Calculates perimeter of a chain code contour.  
  156.   /// \param c Contour (chain code type).  
  157.   /// \return Perimeter of the contour.  
  158.   EXPORT double cvContourChainCodePerimeter(CvContourChainCode const *c);  
  159.   
  160.   /// \fn double cvContourPolygonPerimeter(CvContourPolygon const *p)  
  161.   /// \brief Calculates perimeter of a polygonal contour.  
  162.   /// \param p Contour (polygon type).  
  163.   /// \return Perimeter of the contour.  
  164.   EXPORT double cvContourPolygonPerimeter(CvContourPolygon const *p);  
  165.   
  166.   /// \fn double cvContourPolygonCircularity(const CvContourPolygon *p)  
  167.   /// \brief Calculates the circularity of a polygon (compactness measure).  
  168.   /// \param p Contour (polygon type).  
  169.   /// \return Circularity: a non-negative value, where 0 correspond with a circumference.  
  170.   EXPORT double cvContourPolygonCircularity(const CvContourPolygon *p);  
  171.   
  172.   /// \fn CvContourPolygon *cvSimplifyPolygon(CvContourPolygon const *p, double const delta=1.)  
  173.   /// \brief Simplify a polygon reducing the number of vertex according the distance "delta".  
  174.   /// Uses a version of the Ramer-Douglas-Peucker algorithm (http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).  
  175.   /// \param p Contour (polygon type).  
  176.   /// \param delta Minimun distance.  
  177.   /// \return A simplify version of the original polygon.  
  178.   EXPORT CvContourPolygon *cvSimplifyPolygon(CvContourPolygon const *p, double const delta=1.);  
  179.   
  180.   /// \fn CvContourPolygon *cvPolygonContourConvexHull(CvContourPolygon const *p)  
  181.   /// \brief Calculates convex hull of a contour.  
  182.   /// Uses the Melkman Algorithm. Code based on the version in http://w3.impa.br/~rdcastan/Cgeometry/.  
  183.   /// \param p Contour (polygon type).  
  184.   /// \return Convex hull.  
  185.   EXPORT CvContourPolygon *cvPolygonContourConvexHull(CvContourPolygon const *p);  
  186.   
  187.   /// \fn void cvWriteContourPolygonCSV(const CvContourPolygon& p, const std::string& filename)  
  188.   /// \brief Write a contour to a CSV (Comma-separated values) file.  
  189.   /// \param p Polygon contour.  
  190.   /// \param filename File name.  
  191.   EXPORT void cvWriteContourPolygonCSV(const CvContourPolygon& p, const std::string& filename);  
  192.   
  193.   /// \fn void cvWriteContourPolygonSVG(const CvContourPolygon& p, const std::string& filename, const CvScalar& stroke=cvScalar(0,0,0), const CvScalar& fill=cvScalar(255,255,255))  
  194.   /// \brief Write a contour to a SVG file (http://en.wikipedia.org/wiki/Scalable_Vector_Graphics).  
  195.   /// \param p Polygon contour.  
  196.   /// \param filename File name.  
  197.   /// \param stroke Stroke color (black by default).  
  198.   /// \param fill Fill color (white by default).  
  199.   EXPORT void cvWriteContourPolygonSVG(const CvContourPolygon& p, const std::string& filename, const CvScalar& stroke=cvScalar(0,0,0), const CvScalar& fill=cvScalar(255,255,255));  
  200.   
  201.   ////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  202.   // Blobs  
  203.   
  204.   /// \brief Type of label.  
  205.   /// \see IPL_DEPTH_LABEL  
  206.   typedef unsigned int CvLabel;  
  207.   //typedef unsigned char CvLabel;  
  208.   
  209.   /// \def IPL_DEPTH_LABEL  
  210.   /// \brief Size of a label in bits.  
  211.   /// \see CvLabel  
  212. #define IPL_DEPTH_LABEL (sizeof(cvb::CvLabel)*8)  
  213.   
  214.   /// \def CV_BLOB_MAX_LABEL  
  215.   /// \brief Max label number.  
  216.   /// \see CvLabel.  
  217. #define CV_BLOB_MAX_LABEL std::numeric_limits<CvLabel>::max()  
  218.     
  219.   /// \brief Type of identification numbers.  
  220.   typedef unsigned int CvID;  
  221.   
  222.   /// \brief Struct that contain information about one blob.  
  223.   struct CvBlob  
  224.   {  
  225.     CvLabel label; ///< Label assigned to the blob.  
  226.       
  227.     union  
  228.     {  
  229.       unsigned int area; ///< Area (moment 00).  
  230.       unsigned int m00; ///< Moment 00 (area).  
  231.     };  
  232.       
  233.     unsigned int minx; ///< X min.  
  234.     unsigned int maxx; ///< X max.  
  235.     unsigned int miny; ///< Y min.  
  236.     unsigned int maxy; ///< y max.  
  237.       
  238.     CvPoint2D64f centroid; ///< Centroid.  
  239.       
  240.     double m10; ///< Moment 10.  
  241.     double m01; ///< Moment 01.  
  242.     double m11; ///< Moment 11.  
  243.     double m20; ///< Moment 20.  
  244.     double m02; ///< Moment 02.  
  245.       
  246.     double u11; ///< Central moment 11.  
  247.     double u20; ///< Central moment 20.  
  248.     double u02; ///< Central moment 02.  
  249.   
  250.     double n11; ///< Normalized central moment 11.  
  251.     double n20; ///< Normalized central moment 20.  
  252.     double n02; ///< Normalized central moment 02.  
  253.   
  254.     double p1; ///< Hu moment 1.  
  255.     double p2; ///< Hu moment 2.  
  256.   
  257.     CvContourChainCode contour;           ///< Contour.  
  258.     CvContoursChainCode internalContours; ///< Internal contours.  
  259.   };  
  260.     
  261.   /// \var typedef std::map<CvLabel,CvBlob *> CvBlobs  
  262.   /// \brief List of blobs.  
  263.   /// A map is used to access each blob from its label number.  
  264.   /// \see CvLabel  
  265.   /// \see CvBlob  
  266.   typedef std::map<CvLabel,CvBlob *> CvBlobs;  
  267.   
  268.   /// \var typedef std::pair<CvLabel,CvBlob *> CvLabelBlob  
  269.   /// \brief Pair (label, blob).  
  270.   /// \see CvLabel  
  271.   /// \see CvBlob  
  272.   typedef std::pair<CvLabel,CvBlob *> CvLabelBlob;  
  273.     
  274.   /// \fn unsigned int cvLabel (IplImage const *img, IplImage *imgOut, CvBlobs &blobs);  
  275.   /// \brief Label the connected parts of a binary image.  
  276.   /// Algorithm based on paper "A linear-time component-labeling algorithm using contour tracing technique" of Fu Chang, Chun-Jen Chen and Chi-Jen Lu.  
  277.   /// \param img Input binary image (depth=IPL_DEPTH_8U and num. channels=1).  
  278.   /// \param imgOut Output image (depth=IPL_DEPTH_LABEL and num. channels=1).  
  279.   /// \param blobs List of blobs.  
  280.   /// \return Number of pixels that has been labeled.  
  281.   EXPORT unsigned int cvLabel (IplImage const *img, IplImage *imgOut, CvBlobs &blobs);  
  282.   
  283.   //IplImage *cvFilterLabel(IplImage *imgIn, CvLabel label);  
  284.   
  285.   /// \fn void cvFilterLabels(IplImage *imgIn, IplImage *imgOut, const CvBlobs &blobs)  
  286.   /// \brief Draw a binary image with the blobs that have been given.  
  287.   /// \param imgIn Input image (depth=IPL_DEPTH_LABEL and num. channels=1).  
  288.   /// \param imgOut Output binary image (depth=IPL_DEPTH_8U and num. channels=1).  
  289.   /// \param blobs List of blobs to be drawn.  
  290.   /// \see cvLabel  
  291.   EXPORT void cvFilterLabels(IplImage *imgIn, IplImage *imgOut, const CvBlobs &blobs);  
  292.   
  293.   /// \fn CvLabel cvGetLabel(IplImage const *img, unsigned int x, unsigned int y)  
  294.   /// \brief Get the label value from a labeled image.  
  295.   /// \param img Label image.  
  296.   /// \param x X coordenate.  
  297.   /// \param y Y coordenate.  
  298.   /// \return Label value.  
  299.   /// \see CvLabel  
  300.   EXPORT CvLabel cvGetLabel(IplImage const *img, unsigned int x, unsigned int y);  
  301.   
  302.   /// \fn inline void cvReleaseBlob(CvBlob *blob)  
  303.   /// \brief Clear a blob structure.  
  304.   /// \param blob Blob.  
  305.   /// \see CvBlob  
  306.   EXPORT inline void cvReleaseBlob(CvBlob *blob)  
  307.   {  
  308.     if (blob)  
  309.     {  
  310.       for (CvContoursChainCode::iterator jt=blob->internalContours.begin(); jt!=blob->internalContours.end(); ++jt)  
  311.       {  
  312.     CvContourChainCode *contour = *jt;  
  313.     if (contour)  
  314.       delete contour;  
  315.       }  
  316.       blob->internalContours.clear();  
  317.   
  318.       delete blob;  
  319.     }  
  320.   }  
  321.   
  322.   /// \fn inline void cvReleaseBlobs(CvBlobs &blobs)  
  323.   /// \brief Clear blobs structure.  
  324.   /// \param blobs List of blobs.  
  325.   /// \see CvBlobs  
  326.   EXPORT inline void cvReleaseBlobs(CvBlobs &blobs)  
  327.   {  
  328.     for (CvBlobs::iterator it=blobs.begin(); it!=blobs.end(); ++it)  
  329.     {  
  330.       cvReleaseBlob((*it).second);  
  331.     }  
  332.     blobs.clear();  
  333.   }  
  334.   
  335.   /// \fn CvLabel cvLargestBlob(const CvBlobs &blobs)  
  336.   /// \brief Find largest blob (biggest area).  
  337.   /// \param blobs List of blobs.  
  338.   /// \return Label of the largest blob or 0 if there are no blobs.  
  339.   /// \see cvLabel  
  340.   EXPORT CvLabel cvLargestBlob(const CvBlobs &blobs);  
  341.   
  342.   EXPORT inline CvLabel cvGreaterBlob(const CvBlobs &blobs)  
  343.   {  
  344.     return cvLargestBlob(blobs);  
  345.   }  
  346.   
  347.   /// \fn void cvFilterByArea(CvBlobs &blobs, unsigned int minArea, unsigned int maxArea)  
  348.   /// \brief Filter blobs by area.  
  349.   /// Those blobs whose areas are not in range will be erased from the input list of blobs.  
  350.   /// \param blobs List of blobs.  
  351.   /// \param minArea Minimun area.  
  352.   /// \param maxArea Maximun area.  
  353.   EXPORT void cvFilterByArea(CvBlobs &blobs, unsigned int minArea, unsigned int maxArea);  
  354.   
  355.   /// \fn void cvFilterByLabel(CvBlobs &blobs, CvLabel label)  
  356.   /// \brief Filter blobs by label.  
  357.   /// Delete all blobs except those with label l.  
  358.   /// \param blobs List of blobs.  
  359.   /// \param label Label to leave.  
  360.   EXPORT void cvFilterByLabel(CvBlobs &blobs, CvLabel label);  
  361.   
  362.   /// \fn inline CvPoint2D64f cvCentroid(CvBlob *blob)  
  363.   /// \brief Calculates centroid.  
  364.   /// Centroid will be returned and stored in the blob structure.  
  365.   /// \param blob Blob whose centroid will be calculated.  
  366.   /// \return Centroid.  
  367.   /// \see CvBlob  
  368.   EXPORT inline CvPoint2D64f cvCentroid(CvBlob *blob)  
  369.   {  
  370.     return blob->centroid=cvPoint2D64f(blob->m10/blob->area, blob->m01/blob->area);  
  371.   }  
  372.   
  373.   /// \fn double cvAngle(CvBlob *blob)  
  374.   /// \brief Calculates angle orientation of a blob.  
  375.   /// \param blob Blob.  
  376.   /// \return Angle orientation in radians.  
  377.   /// \see CvBlob  
  378.  EXPORT double cvAngle(CvBlob *blob);  
  379.   
  380.   /// \fn cvSaveImageBlob(const char *filename, IplImage *img, CvBlob const *blob)  
  381.   /// \brief Save the image of a blob to a file.  
  382.   /// The function uses an image (that can be the original pre-processed image or a processed one, or even the result of cvRenderBlobs, for example) and a blob structure.  
  383.   /// Then the function saves a copy of the part of the image where the blob is.  
  384.   /// \param filename Name of the file.  
  385.   /// \param img Image.  
  386.   /// \param blob Blob.  
  387.   /// \see CvBlob  
  388.   /// \see cvRenderBlob  
  389.   EXPORT void cvSaveImageBlob(const char *filename, IplImage *img, CvBlob const *blob);  
  390.     
  391. #define CV_BLOB_RENDER_COLOR            0x0001 ///< Render each blog with a different color. \see cvRenderBlobs  
  392. #define CV_BLOB_RENDER_CENTROID         0x0002 ///< Render centroid. \see cvRenderBlobs  
  393. #define CV_BLOB_RENDER_BOUNDING_BOX     0x0004 ///< Render bounding box. \see cvRenderBlobs  
  394. #define CV_BLOB_RENDER_ANGLE            0x0008 ///< Render angle. \see cvRenderBlobs  
  395. #define CV_BLOB_RENDER_TO_LOG           0x0010 ///< Print blob data to log out. \see cvRenderBlobs  
  396. #define CV_BLOB_RENDER_TO_STD           0x0020 ///< Print blob data to std out. \see cvRenderBlobs  
  397.   
  398.   /// \fn void cvRenderBlob(const IplImage *imgLabel, CvBlob *blob, IplImage *imgSource, IplImage *imgDest, unsigned short mode=0x000f, CvScalar const &color=CV_RGB(255, 255, 255), double alpha=1.)  
  399.   /// \brief Draws or prints information about a blob.  
  400.   /// \param imgLabel Label image (depth=IPL_DEPTH_LABEL and num. channels=1).  
  401.   /// \param blob Blob.  
  402.   /// \param imgSource Input image (depth=IPL_DEPTH_8U and num. channels=3).  
  403.   /// \param imgDest Output image (depth=IPL_DEPTH_8U and num. channels=3).  
  404.   /// \param mode Render mode. By default is CV_BLOB_RENDER_COLOR|CV_BLOB_RENDER_CENTROID|CV_BLOB_RENDER_BOUNDING_BOX|CV_BLOB_RENDER_ANGLE.  
  405.   /// \param color Color to render (if CV_BLOB_RENDER_COLOR is used).  
  406.   /// \param alpha If mode CV_BLOB_RENDER_COLOR is used. 1.0 indicates opaque and 0.0 translucent (1.0 by default).  
  407.   /// \see CV_BLOB_RENDER_COLOR  
  408.   /// \see CV_BLOB_RENDER_CENTROID  
  409.   /// \see CV_BLOB_RENDER_BOUNDING_BOX  
  410.   /// \see CV_BLOB_RENDER_ANGLE  
  411.   /// \see CV_BLOB_RENDER_TO_LOG  
  412.   /// \see CV_BLOB_RENDER_TO_STD  
  413.   EXPORT void cvRenderBlob(const IplImage *imgLabel, CvBlob *blob, IplImage *imgSource, IplImage *imgDest, unsigned short mode=0x000f, CvScalar const &color=CV_RGB(255, 255, 255), double alpha=1.);  
  414.   
  415.   /// \fn void cvRenderBlobs(const IplImage *imgLabel, CvBlobs &blobs, IplImage *imgSource, IplImage *imgDest, unsigned short mode=0x000f, double alpha=1.)  
  416.   /// \brief Draws or prints information about blobs.  
  417.   /// \param imgLabel Label image (depth=IPL_DEPTH_LABEL and num. channels=1).  
  418.   /// \param blobs List of blobs.  
  419.   /// \param imgSource Input image (depth=IPL_DEPTH_8U and num. channels=3).  
  420.   /// \param imgDest Output image (depth=IPL_DEPTH_8U and num. channels=3).  
  421.   /// \param mode Render mode. By default is CV_BLOB_RENDER_COLOR|CV_BLOB_RENDER_CENTROID|CV_BLOB_RENDER_BOUNDING_BOX|CV_BLOB_RENDER_ANGLE.  
  422.   /// \param alpha If mode CV_BLOB_RENDER_COLOR is used. 1.0 indicates opaque and 0.0 translucent (1.0 by default).  
  423.   /// \see CV_BLOB_RENDER_COLOR  
  424.   /// \see CV_BLOB_RENDER_CENTROID  
  425.   /// \see CV_BLOB_RENDER_BOUNDING_BOX  
  426.   /// \see CV_BLOB_RENDER_ANGLE  
  427.   /// \see CV_BLOB_RENDER_TO_LOG  
  428.   /// \see CV_BLOB_RENDER_TO_STD  
  429.   EXPORT void cvRenderBlobs(const IplImage *imgLabel, CvBlobs &blobs, IplImage *imgSource, IplImage *imgDest, unsigned short mode=0x000f, double alpha=1.);  
  430.   
  431.   /// \fn void cvSetImageROItoBlob(IplImage *img, CvBlob const *blob)  
  432.   /// \brief Set the ROI of an image to the bounding box of a blob.  
  433.   /// \param img Image.  
  434.   /// \param blob Blob.  
  435.   /// \see CvBlob  
  436.   EXPORT inline void cvSetImageROItoBlob(IplImage *img, CvBlob const *blob)  
  437.   {  
  438.     cvSetImageROI(img, cvRect(blob->minx, blob->miny, blob->maxx-blob->minx, blob->maxy-blob->miny));  
  439.   };  
  440.   
  441.   ////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  442.   // Color  
  443.   
  444.   /// \fn CvScalar cvBlobMeanColor(CvBlob const *blob, IplImage const *imgLabel, IplImage const *img)  
  445.   /// \brief Calculates mean color of a blob in an image.  
  446.   /// \param blob Blob.  
  447.   /// \param imgLabel Image of labels.  
  448.   /// \param img Original image.  
  449.   /// \return Average color.  
  450.   EXPORT CvScalar cvBlobMeanColor(CvBlob const *blob, IplImage const *imgLabel, IplImage const *img);  
  451.     
  452.   ////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  453.   // Aux  
  454.     
  455.   /// \fn double cvDotProductPoints(CvPoint const &a, CvPoint const &b, CvPoint const &c)  
  456.   /// \brief Dot product of the vectors ab and bc.  
  457.   /// \param a First point.  
  458.   /// \param b Middle point.  
  459.   /// \param c Last point.  
  460.   /// \return Dot product of ab and bc.  
  461.   EXPORT double cvDotProductPoints(CvPoint const &a, CvPoint const &b, CvPoint const &c);  
  462.     
  463.   /// \fn double cvCrossProductPoints(CvPoint const &a, CvPoint const &b, CvPoint const &c)  
  464.   /// \brief Cross product of the vectors ab and bc.  
  465.   /// \param a Point.  
  466.   /// \param b Point.  
  467.   /// \param c Point.  
  468.   /// \return Cross product of ab and bc.  
  469.   EXPORT double cvCrossProductPoints(CvPoint const &a, CvPoint const &b, CvPoint const &c);  
  470.   
  471.   /// \fn double cvDistancePointPoint(CvPoint const &a, CvPoint const &b)  
  472.   /// \brief Distance between two points.  
  473.   /// \param a Point.  
  474.   /// \param b Point.  
  475.   /// \return Distance.  
  476.   EXPORT double cvDistancePointPoint(CvPoint const &a, CvPoint const &b);  
  477.   
  478.   /// \fn double cvDistanceLinePoint(CvPoint const &a, CvPoint const &b, CvPoint const &c, bool isSegment=true)  
  479.   /// \brief Distance between line ab and point c.  
  480.   /// \param a First point of the segment.  
  481.   /// \param b Second point of the segment.  
  482.   /// \param c Point.  
  483.   /// \param isSegment If false then the distance will be calculated from the line defined by the points a and b, to the point c.  
  484.   /// \return Distance between ab and c.  
  485.   EXPORT double cvDistanceLinePoint(CvPoint const &a, CvPoint const &b, CvPoint const &c, bool isSegment=true);  
  486.     
  487.   ////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  488.   // Tracking  
  489.   
  490.   /// \brief Struct that contain information about one track.  
  491.   /// \see CvID  
  492.   /// \see CvLabel  
  493.   struct CvTrack  
  494.   {  
  495.     CvID id; ///< Track identification number.  
  496.   
  497.     CvLabel label; ///< Label assigned to the blob related to this track.  
  498.   
  499.     unsigned int minx; ///< X min.  
  500.     unsigned int maxx; ///< X max.  
  501.     unsigned int miny; ///< Y min.  
  502.     unsigned int maxy; ///< y max.  
  503.       
  504.     CvPoint2D64f centroid; ///< Centroid.  
  505.   
  506.     unsigned int lifetime; ///< Indicates how much frames the object has been in scene.  
  507.     unsigned int active; ///< Indicates number of frames that has been active from last inactive period.  
  508.     unsigned int inactive; ///< Indicates number of frames that has been missing.  
  509.   };  
  510.   
  511.   /// \var typedef std::map<CvID, CvTrack *> CvTracks  
  512.   /// \brief List of tracks.  
  513.   /// \see CvID  
  514.   /// \see CvTrack  
  515.   typedef std::map<CvID, CvTrack *> CvTracks;  
  516.   
  517.   /// \var typedef std::pair<CvID, CvTrack *> CvIDTrack  
  518.   /// \brief Pair (identification number, track).  
  519.   /// \see CvID  
  520.   /// \see CvTrack  
  521.   typedef std::pair<CvID, CvTrack *> CvIDTrack;  
  522.   
  523.   /// \fn inline void cvReleaseTracks(CvTracks &tracks)  
  524.   /// \brief Clear tracks structure.  
  525.   /// \param tracks List of tracks.  
  526.   /// \see CvTracks  
  527.   EXPORT inline void cvReleaseTracks(CvTracks &tracks)  
  528.   {  
  529.     for (CvTracks::iterator it=tracks.begin(); it!=tracks.end(); it++)  
  530.     {  
  531.       CvTrack *track = (*it).second;  
  532.       if (track) delete track;  
  533.     }  
  534.   
  535.     tracks.clear();  
  536.   }  
  537.   
  538.   /// \fn cvUpdateTracks(CvBlobs const &b, CvTracks &t, const double thDistance, const unsigned int thInactive, const unsigned int thActive=0)  
  539.   /// \brief Updates list of tracks based on current blobs.  
  540.   /// Tracking based on:  
  541.   /// A. Senior, A. Hampapur, Y-L Tian, L. Brown, S. Pankanti, R. Bolle. Appearance Models for  
  542.   /// Occlusion Handling. Second International workshop on Performance Evaluation of Tracking and  
  543.   /// Surveillance Systems & CVPR'01. December, 2001.  
  544.   /// (http://www.research.ibm.com/peoplevision/PETS2001.pdf)  
  545.   /// \param b List of blobs.  
  546.   /// \param t List of tracks.  
  547.   /// \param thDistance Max distance to determine when a track and a blob match.  
  548.   /// \param thInactive Max number of frames a track can be inactive.  
  549.   /// \param thActive If a track becomes inactive but it has been active less than thActive frames, the track will be deleted.  
  550.   /// \see CvBlobs  
  551.   /// \see Tracks  
  552.   EXPORT void cvUpdateTracks(CvBlobs const &b, CvTracks &t, const double thDistance, const unsigned int thInactive, const unsigned int thActive=0);  
  553.   
  554. #define CV_TRACK_RENDER_ID            0x0001 ///< Print the ID of each track in the image. \see cvRenderTracks  
  555. #define CV_TRACK_RENDER_BOUNDING_BOX  0x0002 ///< Draw bounding box of each track in the image. \see cvRenderTracks  
  556. #define CV_TRACK_RENDER_TO_LOG        0x0010 ///< Print track info to log out. \see cvRenderTracks  
  557. #define CV_TRACK_RENDER_TO_STD        0x0020 ///< Print track info to log out. \see cvRenderTracks  
  558.   
  559.   /// \fn void cvRenderTracks(CvTracks const tracks, IplImage *imgSource, IplImage *imgDest, unsigned short mode=0x00ff, CvFont *font=NULL)  
  560.   /// \brief Prints tracks information.  
  561.   /// \param tracks List of tracks.  
  562.   /// \param imgSource Input image (depth=IPL_DEPTH_8U and num. channels=3).  
  563.   /// \param imgDest Output image (depth=IPL_DEPTH_8U and num. channels=3).  
  564.   /// \param mode Render mode. By default is CV_TRACK_RENDER_ID|CV_TRACK_RENDER_BOUNDING_BOX.  
  565.   /// \param font OpenCV font for print on the image.  
  566.   /// \see CV_TRACK_RENDER_ID  
  567.   /// \see CV_TRACK_RENDER_BOUNDING_BOX  
  568.   /// \see CV_TRACK_RENDER_TO_LOG  
  569.   /// \see CV_TRACK_RENDER_TO_STD  
  570.   EXPORT void cvRenderTracks(CvTracks const tracks, IplImage *imgSource, IplImage *imgDest, unsigned short mode=0x000f, CvFont *font=NULL);  
  571.   }  
  572. #ifdef __cplusplus  
  573. }  
  574. #endif  
  575.   
  576. /// \fn std::ostream& operator<< (std::ostream& output, const cvb::CvBlob& b)  
  577. /// \brief Overload operator "<<" for printing blob structure.  
  578. /// \return Stream.  
  579. std::ostream& operator<< (std::ostream& output, const cvb::CvBlob& b);  
  580.   
  581. /// \fn std::ostream& operator<< (std::ostream& output, const cvb::CvContourPolygon& p)  
  582. /// \brief Overload operator "<<" for printing polygons in CSV format.  
  583. /// \return Stream.  
  584. std::ostream& operator<< (std::ostream& output, const cvb::CvContourPolygon& p);  
  585.   
  586. /// \fn std::ostream& operator<< (std::ostream& output, const cvb::CvTrack& t)  
  587. /// \brief Overload operator "<<" for printing track structure.  
  588. /// \return Stream.  
  589. std::ostream& operator<< (std::ostream& output, const cvb::CvTrack& t);  
  590. #endif  

8. 编译运行cvblob cmake生成的solution(E:\cvblob_cmake 这个文件夹下的vs2010项目), 分别在Debug模式和Release模式下运行该solution。

这样在E:\cvblob_cmake\lib 目录下的Debug和Release文件夹下分别生成相应的cvblob.lib和cvblob.dll文件。


-----------------------------------------cvblob如何应用-----------------------------------------------------

1. vs2010项目中:

属性VC++ Directories中的Include Directories 里面添加E:\cvblob\cvBlob -- 你的cvblob文件夹

Libraries里添加  E:\cvblob_cmake\lib\Debug   目录

将E:\cvblob_cmake\lib\Debug 文件夹中的cvblob.dll和cvblob.lib两个文件copy到解决方案的debug文件夹里。

同理,将E:\cvblob_cmake\lib\Release文件夹中的cvblob.dll和cvblob.lib两个文件copy到解决方案的release文件夹里

linker-Input属性中:加入 cvblob.lib

2. cpp文件里加入:

#include <cvblob.h>
using namespace cvb;

----------------------------------------------cvblob测试---------------------------------------------------------

在cvblob_cmake解决方案里,有test, test_tracking, test_random,三个用来测试的代码。

按照上面的使用说明,配置好环境。

然后运行。


 

        
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
OpenCV使用的一些经验总结
手把手教你如何实现Python手势识别与控制(含代码及动图)
OpenCV 矩形轮廓检测
学习笔记:使用 OpenCV 识别 QRCode
Python-OpenCV 超简单实用运动侦测算法
OpenCV轮廓检测,计算物体旋转角度
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服