Ask Your Question

Nate's profile - activity

2020-08-26 15:57:09 -0600 received badge  Notable Question (source)
2019-05-09 09:33:16 -0600 received badge  Notable Question (source)
2019-02-15 06:04:03 -0600 received badge  Famous Question (source)
2017-09-26 02:04:03 -0600 received badge  Popular Question (source)
2016-11-29 10:03:30 -0600 received badge  Popular Question (source)
2016-03-09 10:26:20 -0600 commented question Random access on 3-channel, 64-bit, integer image?

You are absolutely correct that the built-in OpenCV functions would not work on a cv::Mat filled with uint64s. I was just hoping to be able to use the container infrastructure to do the memory management. All I really wanted from this exercise was a reliable way to store and retrieve values. Looks like I should probably go ahead and write my own container instead.

Thanks.

2016-03-08 17:10:52 -0600 commented question Random access on 3-channel, 64-bit, integer image?

I am also using 3.1.0. So far, I've only tried this in Debug mode. This is really strange.

2016-03-08 16:44:13 -0600 asked a question Random access on 3-channel, 64-bit, integer image?

Hello,

For a project I'm working on, we need to use a 3-channel, 64-bit, integer image. Since there is no 64-bit integer image type available to us in OpenCV, we build the image with type CV_64FC3 and then just fill it by accessing its locations by pointer. That is, the cv::Mat object thinks it is a double-precision type but we filled in integer data in a bitwise manner. This part seems to work.

What does not work is getting information out of this image in a random-access manner using OpenCV's built-in .at<...>(...) function. I'd like to be able to access a part of the image as a cv::Vec<...> type, without having to use reinterpret_cast< uint64_t>(...) constantly.

Here's the code demonstrating the point:

// Works.
cv::Vec3d vd = img.at< cv::Vec3d>( yy, xx );

// Works.
cv::Vec< double, 3> vd2 = img.at < cv::Vec< double, 3> >( yy, xx );

// Fails with OpenCV assertion failure.
cv::Vec< uint64_t, 3> vi = img.at< cv::Vec< uint64_t, 3> >( yy, xx );

The assertion failure I get with the last line is:

OpenCV Error: Assertion failed (((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file c:\path\to\opencv_301\include\opencv2\core\mat.inl.hpp, line 930

If anyone has any input as to what I am doing wrong, I would love to hear it. I'd really like to do the random-access here using the .at<...>(...) function as illustrated in the failing line above.

Thank you for your time.

2015-09-16 01:34:22 -0600 received badge  Notable Question (source)
2015-01-29 13:58:57 -0600 commented question Using cv::merge(...) to create a 2-channel, 16-bit, signed image?

Never mind. It was a problem with writing to textureImage that was causing the issue.

2015-01-29 12:51:58 -0600 commented answer Cannot read a 10-bit, 3-channel encoded video file as 10-bit

Thanks for the information Victor!

This problem is no longer important to me--I was simply trying to check out if 10-bit video would provide useful extra information for a specific problem. After running my hacky solution, it turned out it wasn't worth pursuing further.

Glad you were able to find something that worked though! This was an annoying problem. :o)

-Nate

2015-01-29 12:51:57 -0600 asked a question Using cv::merge(...) to create a 2-channel, 16-bit, signed image?

Greetings all,

I'm trying to use cv::merge(...) to merge two CV_16S images into one CV_16SC2 image. Unfortunately, when I try to run the code, I get an unhanlded exception on the merge call. If anyone has an idea of how to fix this, I would greatly appreciate it.

Here is my code:

const cv::Mat* MyClass::GetTextureImage( const cv::Mat &frame) {

   // Convert to grayscale.
   cv::Mat grayscaleFrame;
   cv::cvtColor( frame, grayscaleFrame, CV_BGR2GRAY);

   // Get X- and Y- Sobel images.
   cv::Mat sobelX, sobelY;
   cv::Sobel( grayscaleFrame, sobelX, CV_16S, 1, 0, 3, 1.0, 0.0, cv::BORDER_REPLICATE);
   cv::Sobel( grayscaleFrame, sobelY, CV_16S, 0, 1, 3, 1.0, 0.0, cv::BORDER_REPLICATE);

   // Agglomerate Sobel images into a single multi-channel image.
   std::vector< cv::Mat> channels;
   channels.push_back( sobelX);
   channels.push_back( sobelY);
   cv::merge( channels, textureImage);

   return &textureImage;
}

The exception occurs when the cv::merge( ...) call is made. If anyone has any ideas on how to get this to work, I'd love to hear them.

Thanks!

-Nate

2015-01-10 14:59:32 -0600 received badge  Popular Question (source)
2015-01-07 21:45:07 -0600 received badge  Student (source)
2014-09-03 13:52:01 -0600 commented question Is there any way to find an ellipse representation of a convex polygon stored as a set of vertex points in a vector?

The cv::fitEllipse(...) call results in a runtime exception.

2014-08-29 11:12:47 -0600 asked a question Is there any way to find an ellipse representation of a convex polygon stored as a set of vertex points in a vector?

Greetings all,

I have a convex polygon stored as a set of vertex points within a vector. That is,

std::vector< cv::Point> polygon;

I want to find an ellipse representation of this polygon assuming it is solid. Does anyone know of an OpenCV function to find this? I tried using the following code I dug up from some documentation, but it results in an unlabeled unhandled runtime exception after attempting to run the fitEllipse() function.

// Doesn't work.
cv::Mat polyMat( polygon);
cv::RotatedRect ellipse= cv::fitEllipse( polyMat);

Does anyone know of some way to get an ellipse representation of a polygon?

Thanks for your time.

2014-04-17 17:10:12 -0600 commented question Assertion failure with call to cv::calcOpticalFlowPyrLK(...) (ANSWERED)

Alright, I apparently can't answer my own question with a proper answer, so here it is as a comment instead.

The problem was a typo. The variable prevFeatures should be of type cv::vector< cv::Point2f>, not cv::vector< cv::Point2d>. (Note the f and d.) D'oh!

2014-04-17 15:26:54 -0600 commented question Assertion failure with call to cv::calcOpticalFlowPyrLK(...) (ANSWERED)

Looking at the OpenCV source code in lkpyramid.cpp, the error seems like it is a problem with the data format for prevFeatures, though I'm not sure what else I could use... If you have any idea, please let me know.

2014-04-17 15:23:36 -0600 asked a question Assertion failure with call to cv::calcOpticalFlowPyrLK(...) (ANSWERED)

Greetings all,

I am having trouble integrating a call to cv::calcOpticalFlowPyrLK(...) into my (C++) code. Ultimately, I wish to create a video stabilization routine.

I get the following assertion error with the call to cv::calcOpticalFlowPyrLK(...):

OpenCV Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) in cv::calcOpticalFlowPyrLK, file C:\...\opencv\modules\video\src\lkpyramid.cpp, line 593

As far as I can tell, my code follows the example L-K optical flow code in sources\samples\cpp. My code follows. The assertion error occurs with the call directly following the "// PROBLEM OCCURS WITH THIS CALL TO THE L-K OPTICAL FLOW CODE!!!" comment.

If it makes any difference, I am using OpenCV 2.4.7 with Microsoft Visual Studio 2012. I can routinely compile and run other code that utilizes OpenCV.

#include "ConjoinImages.h"

#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/videostab/videostab.hpp"

#include <iostream>
#include <string>
#include <time.h>


int _tmain(int argc, _TCHAR* argv[]) {

   std::string videoFilename= "my_video.mp4";

   // Open input video.
   std::cout<< "Attempting to open input video file:  "<< videoFilename<< std::endl;
   cv::VideoCapture videoIn;
   videoIn.open( videoFilename);
   if( !videoIn.isOpened())
      throw "Error when reading stream!";
   std::cout<< "Video input file open."<< std::endl;

   // Run everything through the stabilizer...
   cv::Mat frame;
   cv::Mat stabilizedFrame;
   bool initialized= false;

   for( unsigned int ii= 0; ii< 30; ++ii) {
      videoIn.read( frame);
   }

   unsigned int frameNum= 0;
   time_t tstart= time( 0);
   while( videoIn.read( frame)) {

      // need to grayscale the image
      if( frame.type()!= CV_8U)
         cv::cvtColor( frame, frame, cv::COLOR_BGR2GRAY);

      // Get the features that need to be tracked.
      int maxCorners= 30;
      cv::vector< cv::Point2f> frameFeatures;
      cv::goodFeaturesToTrack( frame, frameFeatures, maxCorners, 0.01, 30);
      cv::vector< cv::Point2d> prevFeatures;
      cv::goodFeaturesToTrack( stabilizedFrame, prevFeatures, maxCorners, 0.01, 30);

      if( frameFeatures.size()== prevFeatures.size()) {
         // Calculate the Lucas-Kanade optical flow between the two frames.
         cv::vector< uchar> status;
         status.reserve( maxCorners);
         cv::vector< float> errors;
         errors.reserve( maxCorners);

         // PROBLEM OCCURS WITH THIS CALL TO THE L-K OPTICAL FLOW CODE!!!
         cv::calcOpticalFlowPyrLK( stabilizedFrame, frame, prevFeatures, frameFeatures, status, errors);

         // Find the homography transformation between the frames.
         cv::Mat H= cv::findHomography( prevFeatures, frameFeatures);

         if( !H.empty()) {
            // Warp the current frame to match the previous frame.
            cv::warpPerspective( frame, stabilizedFrame, H, frame.size(), cv::INTER_NEAREST| cv::WARP_INVERSE_MAP);
         }
         else {
            stabilizedFrame= frame;
         }
      }
      else {
         stabilizedFrame= frame;
      }

      // Display.
      cv::Mat output;
      ConjoinImages::TwoSideBySide( frame, stabilizedFrame, output);
      cv::imshow( "stabilization", output);
      cv::waitKey( 1);

      ++frameNum;
   }

   return 0;
}

Thank you very much for your time,

-Nate

2014-03-21 15:06:38 -0600 received badge  Critic (source)
2014-02-28 09:58:21 -0600 received badge  Self-Learner (source)
2014-02-28 09:53:06 -0600 answered a question Cannot read a 10-bit, 3-channel encoded video file as 10-bit

Alright, so I didn't get direct 10-bit video reading in OpenCV working per se, but I did get a complicated, "hacky" solution that worked well enough to test whether the extra bit depth going from 8-bit video to 10-bit video was helpful.

So here is what I did:

  1. Used FFMPEG to convert the (10-bit) video from a v210-encoded AVI file into a series of (16-bit) PNG image files, one image file for each frame of the video. Obviously, this takes a tremendous amount of hard drive space. The 10-bits in the original seems to have been stretched to the 16-bit (I assume by adding 6 zero bits of padding to the end).
  2. Read the 16-bit PNG files in sequentially and process them as if they were frames in a video. They actually get read in a CV_16UC3 images!

And that's how I did it. This solution is ugly, hacky, and slow, but it worked.

-Nate

2014-02-06 11:08:33 -0600 commented question Cannot read a 10-bit, 3-channel encoded video file as 10-bit

Of course, if anyone has any alternative tools to OpenCV that might be viable, please post and let me know!

2014-02-06 10:53:13 -0600 commented question Cannot read a 10-bit, 3-channel encoded video file as 10-bit

Well, I downloaded the OpenCV source code and tried to figure out if there was some internal setting for VideoCapture that I could set to get it to read 10-bit video files. I couldn't find any reference to a "CV_RETRIEVE_ANY_DEPTH" setting, but the OpenCV source does have CV_LOAD_IMAGE_ANYDEPTH and IMREAD_ANYDEPTH preprocessor directives. Unfortunately, I could not track down where, if at all, these preprocessor directives might be used in VideoCapture. VideoCapture seems like it is a wrapper on top of IPL calls. Quite frankly, without a detailed system architecture diagram and writeup for OpenCV's video processing system, figuring this out is quite beyond me. At this point, I have to conclude OpenCV is not the right tool for reading and processing high-bitrate video files.

2014-02-05 10:04:45 -0600 commented question Cannot read a 10-bit, 3-channel encoded video file as 10-bit

Thanks for the suggestion StevenPuttemans! I've not dug into the inner workings of OpenCV before. I'll have to download the source code and have a look at the internals of VideoCapture later today.

2014-02-04 23:41:24 -0600 commented question Cannot read a 10-bit, 3-channel encoded video file as 10-bit

Thanks for the feedback keghn! I would love for it to read in as CV_16UC3. At 10 bit, that's actually what I would expect. Unfortunately, there does not seem to be a way to instruct the VideoCapture object to do that. At least not that I have found.

2014-02-03 17:23:55 -0600 asked a question Cannot read a 10-bit, 3-channel encoded video file as 10-bit

Hello all,

I'm running into a problem reading a 10-bit, 3-channel encoded video that was saved from a high definition camera we have. I checked the file using GSpot, and it is encoded using the "Optibase VideoPump 10-bit 4:2:2 Component Y'CbCr" codec (v210).

I can read in frames using OpenCV's VideoCapture class from the file. I can even display the frames just fine using OpenCV's imshow function. Unfortunately, the cv::Mat object that the frames are saved into is of an 8-bit type (CV_8UC3).

Here is the code that I am using to read the video file:

   std::cout<< "Attempting to open file:  "<< filename<< std::endl;
   cv::VideoCapture videoIn;
   videoIn.open( filename);
   if( !videoIn.isOpened())
      throw "Error when reading stream!";

   if( !videoIn.read( frame))
      return 0;

   int type= frame.type();  // Returns 16 (CV_8UC3)

Like I said earlier, frames are being read and displayed, but when I check frame.type(), it returns 16 (CV_8UC3). Since I am trying to get the extra precision by using 10-bits, this is suboptimal.

Does anyone know how to actually read the frames at 10-bit?

Thanks!

-Nate

2013-02-13 18:08:13 -0600 commented question videocapture not working with uncompressed files

I too have the same problem.

2013-02-13 13:34:25 -0600 commented answer Missing header files in OpenCV 2.4.3 pre-built library install

Thank you very much. The problem was that I was using the wrong "include" directory for header files.

Thanks again!

2013-02-13 13:32:33 -0600 received badge  Scholar (source)
2013-02-13 13:32:31 -0600 received badge  Supporter (source)
2013-02-13 12:41:51 -0600 received badge  Editor (source)
2013-02-13 12:41:10 -0600 asked a question Missing header files in OpenCV 2.4.3 pre-built library install

Hello. I have downloaded the pre-built library package for OpenCV 2.4.3, and have followed the short installation routine described on the "Installation for Windows" page. I have Visual Studio set up to check the paths for the header files as well as the library files to link against. It finds the header files just fine.

The problem is, the header file "cv.h" refers to a number of other header files that do not exist. These are: "opencv2/core/core_c.h", "opencv2/core/core.hpp", "opencv2/imgproc/imgproc_c.h", "opencv2/imgproc/imgproc.hpp", "opencv2/video/tracking.hpp", "opencv2/features2d/features2d.hpp", "opencv2/flann/flann.hpp", "opencv2/calib3d/calib3d.hpp", "opencv2/objdetect/objdetect.hpp", "opencv2/legacy/compat.hpp".

I have the directory "include/opencv2", but the only file it contains is "opencv.hpp". None of the files listed above exist in it.

So my question is, what is going on here? Are the installation instructions missing a step or five? How do I fix it and get my program to compile?

If it makes any difference, I am using Visual Studio 2008 on a Windows 8 machine.