Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java cvFlip()闪烁或返回null_Java_Opencv_Camera_Javacv_Iplimage - Fatal编程技术网

Java cvFlip()闪烁或返回null

Java cvFlip()闪烁或返回null,java,opencv,camera,javacv,iplimage,Java,Opencv,Camera,Javacv,Iplimage,我正在做一个项目,其中包括拍摄一个实时的摄像头提要,并将其显示在用户的窗口上 由于默认情况下相机图像的旋转方向是错误的,因此我使用cvFlip翻转它(因此计算机屏幕就像一面镜子),如下所示: 这在大多数情况下都很有效。然而,对于许多用户(主要是在速度更快的PC机上),相机馈送会剧烈闪烁。基本上是显示一个未翻转的图像,然后是翻转的图像,然后是未翻转的图像,反复显示 所以我改变了一些事情来发现问题 while (true) { IplImage currentImage = grab

我正在做一个项目,其中包括拍摄一个实时的摄像头提要,并将其显示在用户的窗口上

由于默认情况下相机图像的旋转方向是错误的,因此我使用cvFlip翻转它(因此计算机屏幕就像一面镜子),如下所示:

这在大多数情况下都很有效。然而,对于许多用户(主要是在速度更快的PC机上),相机馈送会剧烈闪烁。基本上是显示一个未翻转的图像,然后是翻转的图像,然后是未翻转的图像,反复显示

所以我改变了一些事情来发现问题

while (true) 
{   
    IplImage currentImage = grabber.grab();
    IplImage flippedImage = null;
    cvFlip(currentImage,flippedImage, 1); // l-r = 90_degrees_steps_anti_clockwise
    if(flippedImage == null)
    {
        System.out.println("The flipped image is null");
        continue;
    }
    else
    {
        System.out.println("The flipped image isn't null");
        continue;
    }
}
翻转的图像似乎总是返回null。为什么?我做错了什么?这让我快发疯了

如果这是cvFlip()的一个问题,还有什么其他方法可以翻转IplImage


感谢所有帮助过你的人

在将结果存储到翻转图像之前,需要使用空图像而不是空图像初始化翻转图像。此外,您应该只创建一次映像,然后重新使用内存以提高效率。因此,更好的方法如下(未经测试):


谢谢这真是太神奇了,这是我第一次听到有人说用这种方式初始化图像,但现在它似乎对我有用!
while (true) 
{   
    IplImage currentImage = grabber.grab();
    IplImage flippedImage = null;
    cvFlip(currentImage,flippedImage, 1); // l-r = 90_degrees_steps_anti_clockwise
    if(flippedImage == null)
    {
        System.out.println("The flipped image is null");
        continue;
    }
    else
    {
        System.out.println("The flipped image isn't null");
        continue;
    }
}
IplImage current = null;
IplImage flipped = null;

while (true) {
  current = grabber.grab();

  // Initialise the flipped image once the source image information
  // becomes available for the first time.
  if (flipped == null) {
    flipped = cvCreateImage(
      current.cvSize(), current.depth(), current.nChannels()
    );
  }

  cvFlip(current, flipped, 1);
}