小程序,随便记录下下~~
遍历一幅图像,返回 像素值 为 0 的 点的坐标:
#include "stdafx.h"
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include "cvaux.h" //必须引此头文件
using namespace std;
vector<CvPoint> cal_dark(IplImage *img );
int main( int argc, char** argv )
{
IplImage *img = cvLoadImage("rice.png",0);
if(img == NULL)
{
printf("img load failed!\n");
return 0;
}
cvThreshold(img, img, 128, 255, CV_THRESH_BINARY);
vector<CvPoint> myVector = cal_dark(img);
int size = myVector.size();
int i;
for(i = 0; i < size; i++)
{
//printf("[%d, %d]", myVector[i].x, myVector[i].y);
if( i == 10)
printf("\n");
}
///test
IplImage *test = cvCreateImage(cvGetSize(img), 8, 1);
memset(test->imageData, 255, test->widthStep * test->height);