microsoft / MixedRealityCompanionKit

This is a MixedRealityToolkit style repository for code bits and components that may not run directly on Microsoft HoloLens or immersive headsets but instead pair with them to build experiences.
MIT License
595 stars 288 forks source link

Spectator View Calibration App Crashing #86

Closed ccifra closed 7 years ago

ccifra commented 7 years ago

I am trying to get the Spectator View Calibration App working with a WebCam (USE_OPENCV = TRUE). When I run the app I crash after capturing the image in void CalibrationApp::TakeCalibrationPicture(). It looks like it's getting a memory corruption. If I just return without calling HasChessBoard then the app continues to work and I can see the video. The crash will happen trying to free the corners vector if a ChessBoard was not found or a crash (AccessViolation) trying to write the PNG if a chess board was found.

I also needed to change HRESULT OpenCVFrameProvider::Initialize(ID3D11ShaderResourceView colorSRV, ID3D11Texture2D outputTexture)

and add videoCapture->set(cv::CAP_PROP_FRAME_WIDTH, FRAME_WIDTH); videoCapture->set(cv::CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);

Otherwise it would always acquire at 640x480. Not sure if this really means something else if going wrong.

fieldsJacksonG commented 7 years ago

What are the dimensions of your chessboard? findChessboardCorners will throw if your x or y dimensions are 3 or less.

ccifra commented 7 years ago

I am using the chessboard image provided which is 6x4. The app also crashes when I chessboard was not detected.

fieldsJacksonG commented 7 years ago

Are you building release or debug?

Can you provide a callstack

ccifra commented 7 years ago

I am building Debug x64. When I chessboard is visible I get

Exception thrown at 0x00007FF95B8F7310 (opencv_world310.dll) in Calibration.exe: 0xC0000005: Access violation reading location 0x00000299ABE7F000.

With this shortened stack opencv_world310.dll!00007ff95b8f7310() Unknown opencv_world310.dll!00007ff95b8ecc2b() Unknown opencv_world310.dll!00007ff95b8ec8a6() Unknown

Calibration.exe!CalibrationApp::TakeCalibrationPicture() Line 196 C++ Calibration.exe!CalibrationApp::TakeCalibrationPictureAtInterval::l8::() Line 222 C++ Calibration.exe!std::_Invoker_functor::_Call<void (void) & ptr64>(CalibrationApp::TakeCalibrationPictureAtInterval::l8::void (void) & _Obj) Line 1377 C++ Calibration.exe!std::invoke<void (void) & ptr64>(CalibrationApp::TakeCalibrationPictureAtInterval::l8::void (void) & _Obj) Line 1445 C++ Calibration.exe!std::_Invoke_ret<void,void (void) & __ptr64>(std::_Forced<void,1> formal, CalibrationApp::TakeCalibrationPictureAtInterval::__l8::void (void) & <_Vals_0>) Line 1462 C++ Calibration.exe!std::_Func_impl<void (void),std::allocator,void>::_Do_call() Line 214 C++ Calibration.exe!std::_Func_class::operator()() Line 280 C++

The cachedColorMap looks reasonable

ccifra commented 7 years ago

I tried a few more things last night and it turns that that running the Release build works. Not sure if it is expected that only the Release build would work or not but this was not obvious to me.

I do think that videoCapture->set(cv::CAP_PROP_FRAME_WIDTH, FRAME_WIDTH); videoCapture->set(cv::CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);

needs to be added for the capture to work correctly, at least in my case.

fieldsJacksonG commented 7 years ago

Updated - enforce Release for the calibration application, and add cap properties for width and height.

This cap update does not appear to be guaranteed, since some cameras do have an upper bound (Open CV does not attempt to scale the frame up in this case)

In this case, the previous behavior will still be there: the update loop logs that the actual frame dimensions do not match the expected dimensions.

anders-lundgren commented 7 years ago

@ccifra Thanks, also trying to use a webcam (Logitech 920c 1920x1080) with Spectator View. I am using the updated version that includes your changes. However, I still get reported that the resolution is 640x480, and the image from the webcam is also showing in a strange way, suggesting an error in the image stream format. What camera and resolution are you using?

SiriusA7 commented 6 years ago

@inforexperience Did you figure out a fix for the 640x480 issue? Having that same problem when trying to use canon 5dm3 + elgato with opencv 640x480