给定尺寸为 26 * 7 的图像是否有可能在垫子的每一行中包含 78 个单独的颜色值,而另一个可以包含 77

Is it possible that an image of a given size of 26 * 7 can contain 78 separate colour values in each row of the Mat ,and another can contain 77?

本文关键字:包含 一行 单独 另一个 颜色值 图像 是否 有可能      更新时间:2023-10-16
给定

大小为 26 * 7 的图像是否可以在 Mat 的每一行中包含 78,77 或 79 个值?为什么会这样?我有 95 张图像,都是 26 x 7,我发现有些图像每行有 77 个单独的颜色值,有些有 79.这是有问题的,因为我需要一个标准值。

这就是将图像裁剪为 26 x 7 大小的方式。

Mat standard_size=largestObject1(Rect(0,0,26,7));//a template to get the standard _size of a binary image
cv::resize(thresholdi,thresholdi,standard_size.size());

如果我只能将其转换为 26 像素值,我会丢失信息吗?

I create the following code:-
    ofstream in("Eye_Gestures.txt");
    //Eye Graze Class
     IplImage *img2 = cvLoadImage("eye2.bmp");
     Mat imgg2=cvarrToMat(img2);
     Formatted line0i2 = format(imgg2.row(0),"CSV" ); 
     Formatted line1i2 = format(imgg2.row(1),"CSV" ); 
     Formatted line2i2 = format(imgg2.row(2),"CSV" );
     Formatted line3i2 = format(imgg2.row(3),"CSV" ); 
     Formatted line4i2 = format(imgg2.row(4),"CSV" );
     Formatted line5i2 = format(imgg2.row(5),"CSV" ); 
     Formatted line6i2 = format(imgg2.row(6),"CSV" );
     in<<line0i2<<", "<<line1i2<<", "<<line2i2<<", "<<line3i2<<", "<<line4i2<<", "<<line5i2<<", "<<line6i2<<", "<<EyeGraze<<endl;

我需要确保每行为所有 95 张图像存储相同数量的单独颜色值。如果它是 77 个值,则每个图像的所有行都需要为 77。如何确保将 77 而不是 78 或 79 个值传递给文本文件?如何忽略每行的多余值?如何跟踪行上的单独颜色值而不必手动计数它们?

26 x 7 像素的图像包含 7 行,每行 26 像素。一行不会有 27 个像素,更不用说 77 个像素了。你完全糊涂了。

回过头来重新思考你真正想要实现的目标。请注意,文本文件不是图像文件的自然格式。

位图 (bmp) 图像每个像素正好包含 1 个条目。根据您使用的位图类型,这些位图的分辨率可能不同(但始终恒定)。

您用于将 bmp 转换为 csv 文本表示的方法似乎将每个像素序列化为一组 3 个值(可能是 rgb)。如果在宽度为 26px 的图像中,每行获得的条目数与 78 个不同,则很可能在读取文件时犯了一些错误。

常见的错误是表示为空单元格","的 0 值,或者 - 取决于您使用的区域设置 - 十进制逗号字符和 csv 分隔符之间的混淆。

您确定分隔符确实是您在写入输出流时用于分隔行','字符,该输出流被混淆地命名为 in