vc 下 用 opencv 实现的--- 遍历图像,返回值为 a 的 像素点 的坐标

这篇博客简单记录了在VC++环境下利用OpenCV库遍历图像,查找并返回像素值为0的点的坐标的过程。首先创建一个IplImage对象,然后使用memset将图像数据部分全部设置为255,重点在于理解IplImage结构中imageData的含义和widthStep计算图像行长度的方式。
摘要由CSDN通过智能技术生成


小程序,随便记录下下~~


遍历一幅图像,返回 像素值 为 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);
	
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值