首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将圆形菲舍伊图像转换为直线图像的C#编码

将圆形菲舍伊图像转换为直线图像的C#编码
EN

Stack Overflow用户
提问于 2015-11-13 02:08:37
回答 1查看 2.7K关注 0票数 1

我有一个圆形鱼眼图像,想要转换成直线图像。因此,我尝试使用Hugin软件和PanoTools Photoshop插件来获得所需的投影、水平视场(HFoV)值和所需的输出宽度高度。

最后,我有以下情况:原始图像的正方形维数为2650*2650,相机的HFoV为159.36度。

输出直线图像的维数为7200*2650,HFov为155°。

我想问,如何将所有这些参数和值转换为C#算法编码,以便当我提供原始图像时,我将得到校正的输出图像?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-13 03:27:52

即使不是c#,您也可以尝试本实用程序将圆形鱼眼的PPM图像转换为直线投影,它可以给您一个开始。

代码语言:javascript
复制
/*
 * C++ utility to convert a PPM image from circular fisheye into rectilinear projection
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void chomp(char *buffer)
{
  char *end = strchr(buffer, '\0');
  if (end > buffer && *(end - 1) == '\n') *(--end) = '\0';
  if (end > buffer && *(end - 1) == '\r') *(--end) = '\0';
}

int main(int argc, char *argv[])
{
  char linebuf[1024];

  // read PBM signature.
  if (!fgets(linebuf, sizeof(linebuf), stdin)) abort();
  chomp(linebuf);
  if (strcmp(linebuf, "P6") != 0) abort();

  // read dimensions.
  int width, height;
  while (1) {
    if (!fgets(linebuf, sizeof(linebuf), stdin)) abort();
    chomp(linebuf);
    if (linebuf[0] == '#') continue;
    if (sscanf(linebuf, "%d %d", &width, &height) != 2) abort();
    break;
  }
  if (width < 1 || height < 1) abort();

  // read bitdepth.
  int bitdepth;
  while (1) {
    if (!fgets(linebuf, sizeof(linebuf), stdin)) abort();
    chomp(linebuf);
    if (linebuf[0] == '#') continue;
    if (sscanf(linebuf, "%d", &bitdepth) != 1) abort();
    break;
  }
  if (bitdepth != 255) abort();

  // read pixel data.
  unsigned char *pixels[height];
  for (int i = 0; i < height; i++) {
    pixels[i] = new unsigned char[width * 3];
    if (fread(pixels[i], 3, width, stdin) != (size_t) width) abort();
  }


  // write out new image format.
  int midy = height / 2;
  int midx = width / 2;
  int maxmag = (midy > midx ? midy : midx);
  int circum = 2 * M_PI * maxmag;     // c = 2*pi*r
  printf("P6\n");
  printf("%d %d\n", circum, maxmag);
  printf("%d\n", bitdepth);


  char black[3] = {0,0,0};
  for (int y = 0; y < maxmag; y++) {
    for (int x = 0; x < circum; x++) {
      double theta = -1.0 * x / maxmag;       // -(x * 2.0 * M_PI / width);
      double mag = maxmag - y;                // y * 1.0 * maxmag / height;
      int targety = lrint(midy + mag * cos(theta));
      int targetx = lrint(midx + mag * sin(theta));
      if (targety < 0 || targety >= height || targetx < 0 || targetx >= width) {
        fwrite(black, 1, 3, stdout);
      } else {
        fwrite(&pixels[targety][targetx * 3], 1, 3, stdout);
      }
    }
  }

  return 0;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33684836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档