Linux 不接受包含实数的参数

Linux 不接受包含实数的参数

首先,该命令在 Windows 命令提示符下运行良好。

kdu_expand -i /home/tmp/1.jp2 -o /home/tmp/1.tif -region {0.1,0.1},{0.1,0.1}

在 Linux 中,我收到以下错误:

The `-region' argument requires a set of coordinates of the form, "{<top>,<left>},{<height>,<width>}". All quantities must be real numbers in the range 0 to 1.

如果我删除该-region参数并像这样运行:

kdu_expand -i /home/tmp/1.jp2 -o /home/tmp/1.tif

它也可以在 Linux 上运行。

以下是解析参数的代码部分:

    static void
  set_region_of_interest(kdu_args &args, kdu_dims &region, siz_params *siz,
                         double &width_fraction, double &height_fraction)
  /* Parses the `-region' argument to see if a reduced region of interest
     is required.  Returns the region of interest, expressed on the
     original codestream canvas (no geometric transformations) along with
     the fraction of the full image width and height which are represented
     by this region. */
{
  width_fraction = height_fraction = 1.0;
  if (!(siz->get(Sorigin,0,0,region.pos.y) &&
        siz->get(Sorigin,0,1,region.pos.x) &&
        siz->get(Ssize,0,0,region.size.y) &&
        siz->get(Ssize,0,1,region.size.x)))
    assert(0);
  region.size.y -= region.pos.y;
  region.size.x -= region.pos.x;
  if (args.find("-region") == NULL)
    return;
  char *string = args.advance();
  if (string != NULL)
    {
      double top, left, height, width;

      if (sscanf(string,"{%lf,%lf},{%lf,%lf}",&top,&left,&height,&width) != 4)
        string = NULL;
      else if ((top < 0.0) || (left < 0.0) || (height < 0.0) || (width < 0.0))
        string = NULL;
      else
        {
          region.pos.y += (int) floor(region.size.y * top);
          region.pos.x += (int) floor(region.size.x * left);
          region.size.y = (int) ceil(region.size.y * height);
          region.size.x = (int) ceil(region.size.x * width);
          width_fraction = width;
          height_fraction = height;
        }
    }
  if (string == NULL)
    { kdu_error e; e << "The `-region' argument requires a set of coordinates "
      "of the form, \"{<top>,<left>},{<height>,<width>}\". All quantities "
      "must be real numbers in the range 0 to 1."; }
  args.advance();
}

答案1

该参数{0.1,0.1},{0.1,0.1}括号扩展在 Linux shell 中。你可以使用以下命令进行检查echo

$ echo {0.1,0.1},{0.1,0.1}
0.1,0.1 0.1,0.1 0.1,0.1 0.1,0.1

$ echo A{0.1,0.1},{0.1,0.1}B
A0.1,0.1B A0.1,0.1B A0.1,0.1B A0.1,0.1B

为了防止此行为,请将参数括在单引号 ( '...') 中。

kdu_expand -i /home/tmp/1.jp2 -o /home/tmp/1.tif -region '{0.1,0.1},{0.1,0.1}'

相关内容