I have got a problem with running my opencv app on windows 7. I used visual studio C++ 2012 on Windows 8.1 to compile it.
After compiling, everything is ok on Windows 8.1 but when i try to launch it on a laptop with Windows 7 it initializes the camera(blue led next to the camera lights up) then crashes. I havent got any idea what am i doing wrong.
Here is the code:
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
int main( void )
{
cvNamedWindow("TEST" ,cv::WINDOW_NORMAL);
cv::VideoCapture capture;
cv::Mat frame;
capture.open( -1 );
if ( ! capture.isOpened() )
{
printf("--(!)Error initializing the camera\n");
system("pause");
}
while(capture.read(frame))
{
cv::imshow( "TEST", frame );
}
return 0;
}
Thank You for help.
Ok guys. I figured out it may be the problem with the camera being not compatible with opencv249. Thats why it crashes while trying to initialize it. I replaced capture from camera with capture from file and everything went great.
I just wasnt smart enough to figure it out before spamming on forum, sorry.
Related
I've recently started exploring and reading about Microchip's PIC32 MCUs, most specifically for motor control. I had some job done over the years but was a long while and haven't used the IDE with evaluation board since university years. Been using Arduino-compatible boards since or boards, compatible with the Arduino IDE.
So I'm running MPLAB X IDE v6.05 with the latest XC32 Compiler.
My Development board is DT100113 Curiosity Pro board, utilizing PIC32MK0512MCJ064 MCU and an on-board PicKit4 (PKoB4) for programming/debugging/serial connection purposes.
What I try to do is light up the two user LEDs on pins RA10 and RE13 respectively.
As I begin with creating new project, select my device, my program/debug tool and give my project a name, next step is to create a new main.c file.
I create the file and write the following:
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
int main(int argc, char** argv) {
//Define corresponding port bits as outputs (0 = output, 1 = input).
TRISAbits.TRISA10 = 0;
TRISEbits.TRISE13 = 0;
//Latch the outputs to HIGH (1) and hold.
while(1)
{
LATAbits.LATA10 = 1;
LATEbits.LATE13 = 1;
}
return (EXIT_SUCCESS);
}
When I build and run it - nothing happens. Build is successful, connected to programmer, erase/flash device OK, but nothing with the LEDs.
I think I'm missing the #pragma directives (read about that it must be defined first prior anything else), but am unaware on how to set configuration bits (used peripherals, internal clock speed, etc.).
Any pointers to how-to articles, posts, etc. will be highly appreciated. I was not able to find step-by-step tutorial for my development board so far :((
Thank you in advance!
Cheers,
Iliyan
I tried creating a new project, it compiled and ran, but the LEDs were not lit.
Obviously was missing some vital parts in the code.
Application software examples and driver libraries are included as part of the MPLAB Harmony V3 Framework. Add Harmony to 'Embedded' under the 'Tools' tab of the MPLAB IDE.
I had installed CUDA 9.1 previously and tested my OpenCV with the code below, all worked fine but later on I had to remove it and install 8.0. Now the below code gives errors since the previous dlls are searched.
Here is my test code:
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudaarithm.hpp"
using namespace cv;
int main(int argc, char* argv[])
{
try
{
cv::Mat src_host = cv::imread("hdd.png", cv::IMREAD_GRAYSCALE);
cv::cuda::GpuMat dst, src;
src.upload(src_host);
cv::cuda::threshold(src, dst, 128.0, 255.0, cv::THRESH_BINARY);
cv::Mat result_host(dst);
cv::namedWindow("Result", cv::WINDOW_NORMAL);
cv::imshow("Result", result_host);
cv::waitKey();
}
catch (const cv::Exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
return 0;
}
Here is the error:
The code execution cannot proceed because cudart64_91.dll was not found. Reinstalling the program may fix this problem.
It asks for 2-3 more dlls when I click on OK button, but I am not gonna write them here as I suspect the problem arises from the same source.
The problem is rather obvious. The dlls which are tried to be loaded, belong to the uninstalled version of CUDA (9.1), whereas I have now 8.0. I do not know why my Visual Studio 2013 tries to load the previous ones still.
Before anyone asks, yes I do have my newer installation (8.0) in my PATH. I am using Windows 10 x64, if it matters.
The real problem behind your error:
OpenCV was built with CUDA 9.1, this will not change even if you change the CUDA installation, thus it will the DLLs from CUDA 9.1 will always be required for every program that is compiled with OpenCV. Maybe a module does not have this linked and you can use it... but I am almost sure the main ones do and you won't be able to use them.
Possible solutions:
Build OpenCV with CUDA 8.0 then it will require is CUDA 8.0 DLLs and not the 9.1 ones.
Install CUDA 9.1. Both CUDA can be installed in the same computer, that is why they have this _80 or _91, this way you can have both paths and the computer decide which one is needed... I think it is not possible to have BOTH in the same program though, so be careful with this option. If it is only used by OpenCV then it will be ok.
I would recommend the first option, it is safer to stick to one library version...
I'm a beginner to opencv, and I've been trying out some basic things using the library. I've added all the dependencies in VS, so generally the image processing related codes work. However, I am getting the following error on the console for one video-related program:
warning: Error opening file
(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:578) Press any
key to continue.
My code is as follows:
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"
using namespace cv;
int main(int argc, char** argv) {
namedWindow("Video", WINDOW_AUTOSIZE);
VideoCapture cap;
cap.open(argv[1]);
Mat frame;
for (;;) {
cap >> frame;
if (frame.empty()) break;
imshow("Video", frame);
if (waitKey(33) >= 0) break;
}
return 0;
}
I downloaded ffmpeg, and added it my Path environment variable as well, it did not work.
I've searched quite extensively online for this, but to no avail. Any help is appreciated.
Hardware:
Raspberry Pi 2 B
OS: Raspbian (Debian Wheezy, released 05.05.2015)
OpenCV 3.0.0 (released 04.06.2015)
I am working with a camera on the CSI Port of the Raspberry Pi. The command
raspistill -o test.jpg
works fine: it takes a picture and saves it on my Raspberry. So the camera works well.
In June, I displayed the camera and could apply some other functions like detecting edges or lines. A few days ago, I wanted to go further but suddenly I had problems with imshow.
For example the following code worked in June but now returns the error
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/pi/opencv-3.0.0/modules/highgui/src/window.cpp, line 271
terminate called after throwing an instance of 'cv::Exception'
what(): /home/pi/opencv-3.0.0/modules/highgui/src/window.cpp:271: error: (-215) size.width>0 && size.height>0 in function imshow
Here is the code that worked in June:
#include <cv.hpp>
#include <cxcore.hpp>
#include <stdlib.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
int c;
Mat image;
VideoCapture video;
video.open(0);
while(1)
{
video >> image;
imshow("test", image);
c=waitKey(10);
if (c==27)
break;
}
video.release();
return 0;
}
I tried to solve my problem by adding code to mine (like delay, resizing, check if the video opened, check if the image to display is not empty) or by deleting some (like vid.open). However, it still does not work. What I get is always "opening video... video did not open". That means that the test vid.isOpened returns always false. I tried to open another video (even if my camera is not the problem as it works with raspistill, as explained below) but the error is the same, isOpened is false.
Here is my modified code:
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat image;
VideoCapture vid(0); // open the default camera
//VideoCapture vid("/home/pi/video.mp4"); // open a video file
cout << "opening video... ";
waitKey(1000); // add delay if the camera did not have time to open correctly
//vid.set(CV_CAP_PROP_FRAME_WIDTH, 640); // resize
//vid.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
//vid.open(0); // do not open twice, already done in VideoCapture vid(0)
if(!vid.isOpened()) // check if video is successfully opened
{
cout << "video did not open ";
return -1;
}
cout << "video opened correctly ";
namedWindow( "test", CV_WINDOW_AUTOSIZE ); // prepare the window
waitKey(1000); // add delay if the camera did not have time to open correctly
cout << "before while loop ";
while(1)
{
cout << "inside while loop ";
vid >> image; // get a frame from camera
if(!image.empty()) // wait for the image to be taken
{
cout << "displaying image ";
imshow("test", image); // display it
} else {
cout << "image empty ";
}
if (waitKey(10)==27) // waiting for esc key to be pressed for 10ms
break;
}
vid.release();
return 0;
}
Can someone help me fix this? I really do not see why I have this problem now, as it worked perfectly in June, and I did not change anything on my Raspberry.
Thanks in advance for your help!
EDIT: I think the last thing I can do is reinstalling everything (OS Raspbian and OpenCV), as it worked perfectly in June without installing any of the additional libraries you proposed in the answers. I really don't know what changed between June and now, as nobody touched anything on the Raspberry, my code just doesn't work anymore :(
EDIT2: Code used with PiCapture library:
#include <cv.hpp>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include "opencv2/opencv.hpp"
#include "/home/pi/PiCapture/src/PiCapture.cpp"
using namespace cv;
using namespace std;
int main()
{
PiCapture cap;
namedWindow("PiCapture");
cap.open(320, 240, true); // 320 width, 240 height, color true
while(1)
{
Mat img;
img = cap.grab(); // get a frame from camera
if(!image.empty()) // wait for the image to be taken
{
imshow("PiCapture", img); // display it
}
if (waitKey(10)==27) // waiting for esc key to be pressed for 10ms
break;
}
return 0;
}
sudo modprobe bcm2835-v4l2
load the pre-installed video for linux drivers for the cv video capture method
I had a same issue a while back and put together a nice little wrapper for the Raspberry Pi Camera Module so you can easily retrieve images as cv::Mat.
There's a plain c++ version: PiCapture and an OpenFrameworks addon version: ofxCvPiCam
OpenCV does not see raspiCam as a camera. I prefer to use system() command to get frame from raspiCam and save that somewhere in the filesystem. After that you can load it in your program as a image. Or you can try this BlogPost.
I hope it helps.
I am trying to run an exe from this Directx-11 tutorial website:tutorial5 (exe at the end of the page), but I get the error "Could not initialize Direct3d".
I get the same error when I download the solution and run it on Visual Studio 2013 or Visual Studio 2010.
I have installed the latest DirectX (installed using "DirectX
End-User Runtime Web Installer":
link)
I also installed DirectX 9 SDK from here: DirectX 9 SDK June
2010
dxdiag shows Direct3d "Enabled".
I updated the "Intel HD Graphics library on core i5" to the latest driver.
What am I missing? How can I run Directx-11 applications on my machine?
Thanks!
The error happened here, you should check the result of Initialize function to see what's the error.
// Initialize the Direct3D object.
result = m_D3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
if(!result)
{
MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
return false;
}
Another useful tip is to turn on DEBUG mode when create device and swap chain. Try the following code the enable debug mode when creating device(in d3dclass.cpp, add the following code before calling D3D11CreateDeviceAndSwapChain, and don't forget to set the third parameter of this function to flags)
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined( DEBUG ) || defined( _DEBUG )
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// Create the swap chain, Direct3D device, and Direct3D device context.
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, flags, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
if(FAILED(result))
{
return false;
}
Build and run the program in debug mode and see the output in VS's output window.