栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++识别试纸

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++识别试纸

#include 
#include 
#include
#define MAXSIZE 8000
#define column  43//像素列
#define row    56//像素行
#define Threshold 180
using namespace std;
int  test(int* ptr);
void Two_Dimention_arr_traval(int(*gary_ptr1)[column]);
void RGB_Tf_gray(int(*gary_ptr1)[column], int* ptr2);
void Two_Value_TR(int(*gary_ptr1)[column], int threshold);
int positive_ornagetive(int(*gary_ptr1)[column]);

int main()
{
	int data_gray[row][column] = { 0 };
	int data[MAXSIZE] = {0};//存储图像像素值,单通道为最小单位
	int count1=test(data);//统计data数组元素个数
	for(int i = 0; i < 7223;i++ )//便历数组元素
	{
		cout << data[i] << endl;
	}
	cout << "data[]共有" << count1 << "个元素" << endl;
	RGB_Tf_gray(data_gray, data);
	Two_Value_TR(data_gray, Threshold);
	Two_Dimention_arr_traval(data_gray);
	positive_ornagetive(data_gray);

	return 0;
}



int test(int * ptr)
{
	ifstream ifs;
	ifs.open("C:\Users\hp-pc\Desktop\text3.txt", ios::in);
		if (!ifs.is_open()) {
			cout << "文件打开失败" << endl;
			return 0;
		
		}
	char c;//中间变量:暂存从文件中取出的字符
	int c_data[6];//中间数组,与下面变量i结合,完成将文本中字符转换成三通道像素值
	int i = 0;
	int count = 0;//计数:数组中
	while ((c = ifs.get()) != EOF)//循环完成文件中字符读取
	{
		if (c != ' ') {
			if (c != ',') {
				c_data[i] = (int)c - 48;//ascll转换到十进制
				i++;
			}

			if (c == ',') {
				if (i == 1) { ptr[count] = c_data[0];  count++; }
				if (i == 2) { ptr[count] = c_data[0] * 10 + c_data[1]; count++; }
				if (i == 3) { ptr[count] = c_data[0] * 100 + c_data[1] * 10 + c_data[2];  count++; }
				i = 0;
			}
		}
		cout << c << endl;
	}

	ifs.close();//文件关闭
	return count;
}

void RGB_Tf_gray(int (*gary_ptr1)[column],int *ptr2) 
{
	int i=0;
	int j = 0;//行
	int k = 0;//列
	
		for (j = 0; j < row; j++)
		{
			for(k=0;k
				gary_ptr1[j][k] = (ptr2[i] + ptr2[i + 1] + ptr2[i + 2]) / 3;
				i += 3;
			}
			
		}	
}

void Two_Dimention_arr_traval(int(*gary_ptr1)[column])
{
	int i, j;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < column; j++)
		{
			cout <
	int i, j;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < column; j++)
		{
			if (gary_ptr1[i][j] > threshold)gary_ptr1[i][j] = 255;
			else gary_ptr1[i][j] = 0;
			
		}

	}
	
}

int positive_ornagetive(int(*gary_ptr1)[column])
{
	int i, j;
	int jump_location = 0;
	int jump_number = 0;
	for (i = 0; i < column; i++)
	{
		for (j = 0; j < row-1; j++)
		{
			if ((gary_ptr1[j][i] - gary_ptr1[j + 1][i]) != 0) {
				jump_number++; jump_location
					+= j;
			}
			
		}

	}
	jump_location = jump_location /( 2 * column);
	cout << "跳变点数为" << jump_number << endl;
	cout << "跳变位置为" << jump_location << endl;
	return 1;

}入代码片
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/836275.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号