opencv投影

// OpencvTest.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv/ml.h"
#include <afx.h>
#include "math.h"


using namespace cv;
using namespace std;

Mat hp, vp;

void HProjection(const Mat& src, Mat& dst) 

 // accept only char type matrices  
 CV_Assert(src.depth() != sizeof(uchar)); 

 dst.create(src.rows, 1, CV_32F); 

 int i, j; 
 const uchar* p; 
 float* p_dst; 
 p_dst = dst.ptr<float>(0); 
 for(i = 0; i < src.rows; i++)
 { 
  p = src.ptr<uchar>(i);    
  p_dst[i] = 0; 
  for(j = 0; j < src.cols; j++)
  { 
   p_dst[i] += p[j]; 
  } 
 } 
}

void VProjection(const Mat& src, Mat& dst)
{
 CV_Assert(src.depth() != sizeof(uchar));
 dst.create(1, src.cols, CV_32F);

 int i,j;
 const uchar* p;
 float * p_dst = dst.ptr<float>(0);

 for (i = 0; i < src.cols; i++)
 {
  p_dst[i] = 0;
  for (j=0; j < src.rows; j++)
  {
   p = src.ptr<uchar>(j);
   p_dst[i] += p[i];
   
  }
  cout << p_dst[i] << endl;
 }
}

int _tmain(int argc, _TCHAR* argv[])
{
 Mat src1Test = (Mat_<uchar>(3,3) << 1,2,3,4,5,6,7,8,9);
 

 HProjection(src1Test, hp);
 VProjection(src1Test, vp);

 cout << src1Test << endl;
 cout << "hp:" << endl;
 cout << hp << endl;
 cout << "vp" << endl;
 cout << vp << endl;

 waitKey(0);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值