双目立体视觉匹配程序

  • C1_431664
    了解作者
  • matlab
    开发工具
  • 368.4KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-02-22 10:00
    上传日期
运用matlab进行双目立体视觉的深度信息匹配,最后导出彩色深度图
双目立体视觉匹配程序
  • siftDemoV4
  • siftDemoV4
  • sift
    44KB
  • LICENSE
    1KB
  • defs.h
    1.9KB
  • box.pgm
    70.6KB
  • basmati.pgm
    45.3KB
  • match.m
    1.9KB
  • README
    7.8KB
  • scene.pgm
    192KB
  • siftWin32.exe
    92KB
  • Makefile
    631B
  • util.c
    7.3KB
  • appendimages.m
    461B
  • book.pgm
    95.4KB
  • sift.m
    2.4KB
  • showkeys.m
    1.7KB
  • match.c
    4.8KB
内容介绍
/************************************************************************ Demo software: Invariant keypoint matching. Author: David Lowe util.c: This file contains routines for creating floating point images, reading and writing PGM files, reading keypoint files, and drawing lines on images: Image CreateImage(row,cols) - Create an image data structure. ReadPGM(filep) - Returns list of images read from the PGM format file. WritePGM(filep, image) - Writes an image to a file in PGM format. DrawLine(image, r1,c1,r2,c3) - Draws a white line on the image with the given row, column endpoints. ReadKeyFile(char *filename) - Read file of keypoints. *************************************************************************/ #include "defs.h" #include <stdarg.h> /* -------------------- Local function prototypes ------------------------ */ float **AllocMatrix(int rows, int cols); void SkipComments(FILE *fp); /*------------------------ Error reporting ----------------------------*/ /* This function prints an error message and exits. It takes a variable number of arguments that function just like those in printf. */ void FatalError(char *fmt, ...) { va_list args; va_start(args, fmt); fprintf(stderr, "Error: "); vfprintf(stderr, fmt, args); fprintf(stderr,"\n"); va_end(args); exit(1); } /*----------------- Routines for image creation ------------------------*/ /* Create a new image with uninitialized pixel values. */ Image CreateImage(int rows, int cols) { Image im; im = (Image) malloc(sizeof(struct ImageSt)); im->rows = rows; im->cols = cols; im->pixels = AllocMatrix(rows, cols); im->next = NULL; return im; } /* Allocate memory for a 2D float matrix of size [row,col]. This returns a vector of pointers to the rows of the matrix, so that routines can operate on this without knowing the dimensions. */ float **AllocMatrix(int rows, int cols) { int i; float **m, *v; m = (float **) malloc(rows * sizeof(float *)); v = (float *) malloc(rows * cols * sizeof(float)); for (i = 0; i < rows; i++) { m[i] = v; v += cols; } return (m); } /*----------------- Read and write PGM files ------------------------*/ /* This reads a PGM file from a given filename and returns the image. */ Image ReadPGMFile(char *filename) { FILE *file; /* The "b" option is for binary input, which is needed if this is compiled under Windows. It has no effect in Linux. */ file = fopen (filename, "rb"); if (! file) FatalError("Could not open file: %s", filename); return ReadPGM(file); } /* Read a PGM file from the given file pointer and return it as a float Image structure with pixels in the range [0,1]. If the file contains more than one image, then the images will be returned linked by the "next" field of the Image data structure. See "man pgm" for details on PGM file format. This handles only the usual 8-bit "raw" PGM format. Use xv or the PNM tools (such as pnmdepth) to convert from other formats. */ Image ReadPGM(FILE *fp) { int char1, char2, width, height, max, c1, c2, c3, r, c; Image image, nextimage; char1 = fgetc(fp); char2 = fgetc(fp); SkipComments(fp); c1 = fscanf(fp, "%d", &width); SkipComments(fp); c2 = fscanf(fp, "%d", &height); SkipComments(fp); c3 = fscanf(fp, "%d", &max); if (char1 != 'P' || char2 != '5' || c1 != 1 || c2 != 1 || c3 != 1 || max > 255) FatalError("Input is not a standard raw 8-bit PGM file.\n" "Use xv or pnmdepth to convert file to 8-bit PGM format.\n"); fgetc(fp); /* Discard exactly one byte after header. */ /* Create floating point image with pixels in range [0,1]. */ image = CreateImage(height, width); for (r = 0; r < height; r++) for (c = 0; c < width; c++) image->pixels[r][c] = ((float) fgetc(fp)) / 255.0; /* Check if there is another image in this file, as the latest PGM standard allows for multiple images. */ SkipComments(fp); if (getc(fp) == 'P') { ungetc('P', fp); nextimage = ReadPGM(fp); image->next = nextimage; } return image; } /* PGM files allow a comment starting with '#' to end-of-line. Skip white space including any comments. */ void SkipComments(FILE *fp) { int ch; fscanf(fp," "); /* Skip white space. */ while ((ch = fgetc(fp)) == '#') { while ((ch = fgetc(fp)) != '\n' && ch != EOF) ; fscanf(fp," "); } ungetc(ch, fp); /* Replace last character read. */ } /* Write an image to the file fp in PGM format. */ void WritePGM(FILE *fp, Image image) { int r, c, val; fprintf(fp, "P5\n%d %d\n255\n", image->cols, image->rows); for (r = 0; r < image->rows; r++) for (c = 0; c < image->cols; c++) { val = (int) (255.0 * image->pixels[r][c]); fputc(MAX(0, MIN(255, val)), fp); } } /* Draw a white line from (r1,c1) to (r2,c2) on the image. Both points must lie within the image. */ void DrawLine(Image image, int r1, int c1, int r2, int c2) { int i, dr, dc, temp; if (r1 == r2 && c1 == c2) /* Line of zero length. */ return; /* Is line more horizontal than vertical? */ if (ABS(r2 - r1) < ABS(c2 - c1)) { /* Put points in increasing order by column. */ if (c1 > c2) { temp = r1; r1 = r2; r2 = temp; temp = c1; c1 = c2; c2 = temp; } dr = r2 - r1; dc = c2 - c1; for (i = c1; i <= c2; i++) image->pixels[r1 + (i - c1) * dr / dc][i] = 1.0; } else { if (r1 > r2) { temp = r1; r1 = r2; r2 = temp; temp = c1; c1 = c2; c2 = temp; } dr = r2 - r1; dc = c2 - c1; for (i = r1; i <= r2; i++) image->pixels[i][c1 + (i - r1) * dc / dr] = 1.0; } } /*---------------------- Read keypoint file ---------------------------*/ /* This reads a keypoint file from a given filename and returns the list of keypoints. */ Keypoint ReadKeyFile(char *filename) { FILE *file; file = fopen (filename, "r"); if (! file) FatalError("Could not open file: %s", filename); return ReadKeys(file); } /* Read keypoints from the given file pointer and return the list of keypoints. The file format starts with 2 integers giving the total number of keypoints and the size of descriptor vector for each keypoint (currently assumed to be 128). Then each keypoint is specified by 4 floating point numbers giving subpixel row and column location, scale, and orientation (in radians from -PI to PI). Then the descriptor vector for each keypoint is given as a list of integers in range [0,255]. */ Keypoint ReadKeys(FILE *fp) { int i, j, num, len, val; Keypoint k, keys = NULL; if (fscanf(fp, "%d %d", &num, &len) != 2) FatalError("Invalid keypoint file beginning."); if (len != 128) FatalError("Keypoint descriptor length invalid (should be 128)."); for (i = 0; i < num; i++) { /* Allocate memory for the keypoint. */ k = (Keypoint) malloc(sizeof(struct KeypointSt)); k->next = keys; keys = k; k->descrip = malloc(len); if (fscanf(fp, "%f %f %f %f", &(k->row), &(k->col), &(k->scale), &(k->ori)) != 4) FatalError("Invalid keypoint file format."); for (j = 0; j < len; j++) { if (fscanf(fp, "%d", &val) != 1 || val < 0 || val > 255) FatalError("Invalid keypoint file value."); k->descrip[j] = (unsigned char) val; } } return keys; }
评论
    相关推荐
    • Matlab合集
      冈萨雷斯数字图像处理MATLAB版.中文版+数字图像处理第二版中文版(冈萨雷斯)+MATLAB-R2014a完全自学一本通+MATLAB R2016a完全自学一本通 素材文件+[模式识别与智能计算:MATLAB技术实现(第2版)].杨淑莹.扫描版
    • MATLAB教程
      MATLAB教程MATLAB教程MATLAB教程MATLAB教程MATLAB教程MATLAB教程
    • MATLAB
      MATLAB 该项目是在matlab上完成的,涉及创建和移动宇宙飞船和机器人。 太空飞船和机器人是使用Matlab中的简单几何形状创建的,并通过连续变换矩阵进行移动。 这个项目教我如何使用变换矩阵(旋转,平移等)的概念...
    • MATLAB基础
      一本学习matlab的一本好书
    • MATLAB编译器
      基于MATLAB 2018b版本介绍MATLAB编译器。介绍如何利用编译器将MATLAB代码编译为独立应用程序或组件,并在没有安装MATLAB的计算机上进行部署。
    • matlabruntime
      通过奇点容器运行您的matlab项目 可以在没有MATLAB的容器中运行matlab代码。 为此,我们首先需要通过Matlab编译器在本地构建相应的Matlab代码的独立应用程序,然后使用具有Matlab运行时( 的容器)运行该应用程序 )...
    • matlab实现
      matlab实现 matlab实现matlab实现matlab实现matlab实现
    • matlab 教程
      matlab 信号处理资料,里面包含信号处理pdf文档,一些杂乱的程序和命令等
    • matlab教程
      matlab教程,PPT格式,包含 matlab基本知识、matlab入门、matlab作图、线性规划、无约束优化、非线性规划、统计工具箱、差值、微分方程等多项知识点,并且每个知识点独立成为PPT,内还含有matlab信号处理详解等文档...
    • matlab简介
      1.MATLAB 开发环境 1.1 MATLAB 的视窗环境 进入MATLAB之后,会看到一个视窗MATLAB Command Window称为指令视窗,它是你键入指令的地方同时 MATLAB也将计算结果显示在此。 1.2 简易计算 我们先从MATLAB的...