我已经.txt使用 C 语言的文件处理工具多次打开文件。但是当我尝试使用与文本文件相同的过程打开图像文件时,我就是做不到。我什至尝试以二进制模式打开图像文件"rb"。
这是我正在使用的代码:
#include "file.h"
#include "stdio.h"
main()
{
FILE *fp;
char ch;
fp = fopen("D:\\setups\\tcc\\Bluehills.bmp", "rb+");
if(fp == NULL)
{
printf("Error in opening the image");
fclose(fp);
exit(0);
}
printf("Successfully opened the image file");
while((ch = fgetc(fp)) != EOF)
{
printf("%c", ch);
}
printf("\nWriting to o/p completed");
}
Run Code Online (Sandbox Code Playgroud)
我需要修改什么才能获得原样的图像?当我将图像输出定向到 DOS 窗口时,至少必须出现单色像素图像。
Opencv 社区提供了一些例程来加载图像,访问图像的值。事实上,在大多数 opencv 教程文档中,我们会找到许多函数的 C 版本。您可以查找此链接C_Api 函数。
但是,有一个免责声明:与 C++/python 例程相比,opencv 的 C 例程较少。但如果你别无选择,他们总是可以依靠的。
此外,互联网社区认为使用 C(Opencv 例程)目的是一种过时的方法,原因有两个:
可用的例程数量很少(我遇到过这个问题)。
MatC++ 的IplImage/cvMat对象和 C 的对象之间没有兼容性。
包含stdio.h, highgui.h, cv.h库后的一些示例代码(模糊):
`int main( int argc, char** argv ) {
IplImage* img = 0;
IplImage* out = 0;
if( argc < 2 ) {
printf( "Usage: Accepts one image as argument\n" );
exit( EXIT_SUCCESS );
}
img = cvLoadImage( argv[1] );
if( !img ) {
printf( "Error loading image file %s\n", argv[1]);
exit( EXIT_SUCCESS );
}
out = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );
cvSmooth( img, out, CV_GAUSSIAN, 3, 3 );
cvReleaseImage( &img );
cvReleaseImage( &out );
cvDestroyWindow( "Example1" );
cvDestroyWindow( "Output" );
return EXIT_SUCCESS;
Run Code Online (Sandbox Code Playgroud)
}`