Ask Your Question

closecall's profile - activity

2017-03-14 04:24:38 -0600 commented question image.data won't load

Have you tied using a hardcoded static path to your image? What's your input for argv?

2017-03-13 08:13:15 -0600 asked a question Multiple calls to cv::ogl::Texture2D.copyFrom() results in cv::Exception (-219)

I am rendering two views per frame on an HMD and it's kind of complicated right now because I use OpenCV to load images and process intermediary results and the rest is OpenGL, but I still want it to work. I am using OpenCV 3.1 and any help would be greatly appreciated, even if you have just some advice.

Application details:

Per view (left and right eye) I take four images as cv::Mat and copy them into four cv::ogl::Texture2D objects. Then I bind these textures to active OpenGL textures to configure my shader and draw to a framebuffer. I read the pixels of the frame buffer again (glReadPixels()) as a cv::Mat and do some postprocessing. This cv::Mat ("synthView") is getting copied to another cv::ogl::Texture2D which is rendered on a 2D screenspace quad for the view.

Here's some console output I logged for each call to the cv::ogl::Texture2D objects. No actual code!

// First iteration for my left eye view
colorImageTexture[LEFT].copyFrom(imageLeft, true); //view1
colorImageTexture[RIGHT].copyFrom(imageRight, true); //view1
depthImageTexture[LEFT].copyFrom(depthLeft, true); //view1
depthImageTexture[RIGHT].copyFrom(depthRight, true); //view1

colorImageTexture[i].bind(); //left
depthImageTexture[i].bind(); //left
colorImageTexture[i].bind(); //right
depthImageTexture[i].bind(); //right

synthesizedImageTexture.copyFrom(synthView, true); //frame0, left_eye done

// Second iteration for my right eye view, reusing colorImageTexture[LEFT] the first time
colorImageTexture[LEFT].copyFrom(imageLeft, true); //view2 // cv::Exception!

The code was working when I catched the exceptions and used the Oculus DK2 instead of the CV1. As you can see, I can run through one rendered view, but trying to render the second view will throw an exception in the copyFrom method at gl::Buffer::unbind(ogl::Buffer::PIXEL_UNPACK_BUFFER).

The exception occurs after all ogl::Texture2D objects have been used once and the first one gets "reused", which means that it will not call ogl::Texture2D::create(...) in the copyFrom() function!


Details of the cv::Exception:

code: -219

err: The specified operation is not allowed in the current state

func: cv::ogl::Buffer::unbind

file: C:\\SDKs\\opencv3.1\\sources\\modules\\core\\src\\opengl.cpp

Call stack details:

cv::ogl::Texture2D::copyFrom(const cv::_InputArray &arr, bool autoRelease);

gets called from my calls, which invokes

ogl::Buffer::unbind(ogl::Buffer::PIXEL_UNPACK_BUFFER);

In that, there is an OpenGL call to

gl::BindBuffer(target, 0); // target is "ogl::Buffer::PIXEL_UNPACK_BUFFER"

with a direct call to CV_CheckGlError(); afterwards, which throws the cv::exception. HAVE_OPENGL is apparently not defined in my code. The GL error is a GL_INVALID_OPERATION.

According to the specification of glBindBuffer:

void glBindBuffer(GLenum target,
                  GLuint buffer);

While a non-zero buffer object name is bound, GL operations on the target to which it is bound affect the bound buffer object, and queries of the target to which it is bound return state from the bound buffer object. While buffer object name zero is bound, as in the initial state, attempts to modify or query state on the target to which it ...

(more)
2016-11-29 03:22:22 -0600 received badge  Editor (source)
2016-11-29 02:14:09 -0600 asked a question cv::Mat to DirectX11 Texture (OpenCV 3.1.0)

Let's say I'm trying to display my webcam image in a game in DirectX11. I am using the prebuilt 3.1.0 libraries and I seem to be having difficulties with OpenCL while converting a Mat to a DirectX texture. I am using VS2013 Update 5 under Win10 and I am building a x64 windows application. The machine uses 2 x Nvidia Geforce GTX1080.

// CREATING DIRECTX TEXTURE
ID3D11Texture2D* myTexture = 0;
D3D11_TEXTURE2D_DEC desc_rgba;
desc_rgba.Width = 1024;
desc_rgba.Height = 768;
desc_rgba.MipLevels =1;
desc_rgba.ArraySize =1;
desc_rgba.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // should be CV_8UC4
desc_rgba.SampleDesc.Count = 1;
desc_rgba.SampleDesc.Quality = 0;
desc_rgba.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc_rgba.Usage = D3D11_USAGE_DYNAMIC;
desc_rgba.CPUAccessFalgs = D3D11_CPU_ACCESS_WRITE;
desc_rgba.MiscFlags = 0;

HRESULT r = DIRECTX.Device->CreateTexture2D(&desc_rgba, 0, &myTexture);
if (FAILED(r)){
    throw std::runtime_error("Can't create DX texture!");
}

cv::ocl::Context oclContext;
if (cv::ocl::haveOpenCL()){// Returns 1        
    // NEW: Exception right here, writing at 0x0000...0
    oclContext = cv::directx::ocl::initializeContextFromD3D11Device(DIRECTX.Device); 
} 

//...

// GAME LOOP
// CV::MAT --> DIRECTX
cv::Mat webCamImg = ...; // get valid image somehow
cv::Mat convertedImg;
cv::cvtColor(webCamImg, convertedImage, CV_BGR2BGRA); //CV_8UC3 -> CV_8UC4
cv::directx::convertToD3D11Texture2D(convertedImg, myTexture); // (OLD: Throws exception!)

initializeContextFromD3D11Device is troubling me. Even all the samples are not working for me because of this line, but the OpenGL one does.

Here's the config log: http://pastebin.com/8i34sSRM

Update Edit 2: After reinstalling my graphics drivers and CUDA 7.5, haveOpenCL() returns 1 suddenly. Also, I don't jump to the code anymore when I get a cv::Exception(). What's up with that?


OLD! (EDIT1: Added cv::ocl::Context code and new exception (-222).)

EDIT2: Problem shifted to the cv::ocl::Context initialization after updating drivers.

EDIT3: Tried out the official DirectX11 sample code (EXAMPLE_DIRECTX d3d11_interop) and I get the same exception at the same place.

EDIT4:

  • EXAMPLE_DIRECTX d3d10_interop fails at the same line.
  • EXAMPLE_DIRECTX d3d9_interop fails at the same line.
  • EXAMPLE_DIRECTX d3d9ex_interop fails at the same line.
  • EXAMPLE _OPENGL opengl_interop actually works!
2016-09-01 02:06:46 -0600 received badge  Enthusiast
2016-08-24 01:08:22 -0600 received badge  Scholar (source)
2016-08-23 02:48:12 -0600 commented answer Which cameras do you recommend for stereo with a larger baseline in OpenCV?

Basically I want to make a see-through AR application. Imagine three cameras (A,B,C) mounted outside to a wall ("#") with windows ("__"): A#__#B#__#C The distance between the cameras is 1 m, so I cannot make it smaller. In the wall part, I want to render the outside from my virtual viewpoint. Hm, I think a depth range starting at 0.5 m seems good.

A large baseline makes my stereo very far-sighted, right? With z=(f*b)/d, assuming a 50 mm focal length and a baseline of 1 m, we get for a disparity of 0.1 m (or is it pixels?) a depth of 0.5 m.

2016-08-22 02:34:31 -0600 commented answer Which cameras do you recommend for stereo with a larger baseline in OpenCV?

Thank you for your great reply. My final goal baseline is 1 m (depends on some other structure), which is huge, I think. Also, I think it's not possible right now to have that high FPS even with GPU algorithms at the moment. All your points are valid and I will keep them in mind, so thanks again! I think I will start with some good webcams and fix them to a rig.

2016-08-22 02:21:04 -0600 received badge  Supporter (source)
2016-08-19 17:07:01 -0600 received badge  Student (source)
2016-08-19 04:58:35 -0600 asked a question Which cameras do you recommend for stereo with a larger baseline in OpenCV?

I want to have a pair of cameras for a stereo research project (disparity maps etc.) with OpenCV from live feed video.

I am thinking of some modern USB HD webcams, but I am not entirely sure because of codec or other issues with OpenCV.

I also want to have a larger baseline compared to stereo cams, so I need to have two separate cameras instead of a stereo camera.

The optimal case would be a simultaneous lag-free full HD video capture of both cameras in OpenCV with high FPS and a way to fix the cameras in place.


1) Which issues could present themselves with OpenCV? What should I pay attention to when I buy?

2) What kind of cameras do you recommend? Do you have a specific camera in mind?