4.0opencv库+vs2017配置及一般区域分块处理方法

1.opencv库配置

1.opencv官网(https://opencv.org/)下载3.40版本opencv库,直接解压后放在非中文路径下;

2.配置电脑环境:右键点开桌面此电脑属性--高级系统设置--环境变量--Path--编辑,把之前解压好的OpenCV路径下的bin路径添加到Path系统环境变量中。重启一下

3.最后操作,在VS2017中创建一个新项目(debug,x64)。

打开属性管理器,右键属性,找到vc++目录——包含目录——右键选择编辑,添加opencv build目录下的include,以及include目录下的opencv,opencv2。

找到 vc++目录——库目录——右键选择编辑,添加build中的x64/vs14/lib;

找到链接器——输入——附加依赖项,添加opencv_world340d.lib。

4.配置完毕 开始使用。

测试一下

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;

int main()
{
    Mat image = imread(
"");  //存放自己图像的路径
    imshow(
"显示图像", image);
    waitKey(
0);
   
return 0;
}




2.分块处理方法

void Seed_Filling(const cv::Mat& binImg, cv::Mat& lableImg)  
{
 if (binImg.empty() ||
  binImg.type() != CV_8UC1)
 {
      return;
 }
 lableImg.release();
 binImg.convertTo(lableImg, CV_32SC1);
 int label = 1;
 int rows = binImg.rows - 1;
 int cols = binImg.cols - 1;
 for (int i = 1; i < rows - 1; i++)
 {
  int* data = lableImg.ptr<int>(i);
  for (int j = 1; j < cols - 1; j++)
  {
   if (data[j] == 1)
   {
    stack<pair<int, int>> neighborPixels;
    neighborPixels.push(pair<int, int>(i, j));     
    ++label;  
    while (!neighborPixels.empty())
    {
     pair<int, int> curPixel = neighborPixels.top(); 
     int curX = curPixel.first;
     int curY = curPixel.second;
     lableImg.at<int>(curX, curY) = label;
     neighborPixels.pop();
     if (lableImg.at<int>(curX, curY - 1) == 1)
     } 
      neighborPixels.push(pair<int, int>(curX, curY - 1));
     }
     if (lableImg.at<int>(curX, curY + 1) == 1)
     { 
      neighborPixels.push(pair<int, int>(curX, curY + 1));
     }
     if (lableImg.at<int>(curX - 1, curY) == 1)
     {
      neighborPixels.push(pair<int, int>(curX - 1, curY));
     }
     if (lableImg.at<int>(curX + 1, curY) == 1)
     {
      neighborPixels.push(pair<int, int>(curX + 1, curY));
     }
    }
   }
  }
 }
 cout << label << endl;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值