Problem :Debuging in Visual C++ 2008 for opencv C++ - c++

I am using openCV 2.1 on visual c++ 2008, I made a simple program and when I tried to debug it in an step into manner, since I want to know the source of the function but cvLoadImage, Its gives an error "the source is not found for this function " and it automatically goes to the next statement. This happens all the time for each line of the program.
I am new to this kind of setting to be specified for the debug to go into the libraries and work properly. can any one please help me on this.
the code I used is
int _tmain(int argc, _TCHAR* argv[])
{
IplImage *img = cvLoadImage("funny-pictures-cat-goes-pew.jpg");
cvNamedWindow("Image:",1);
cvShowImage("Image:",img);
cvWaitKey();
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}

I saw this on the OpenCV homepage. Did you include the headers and the picture? You might want to revise and check your code to see if it matches with the one on the bottom of http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010.

Related

How do I graph data in c++?

I am trying to make a graph using graphics.h in c++. I was following a tutorial on youtube. It seems that either due to the age of the video (perhaps the syntax has changed slightly?) or a problem on my end; I cannot even get a separate window for my graph to open. I am in completely uncharted waters for me as the limit of my coding knowledge is what you would expect to learn from a first-semester coding class. I am using DEV C++ and am compiling using "TDM-GCC 4.9.2 32-bit Release" (because the 64 bit release gives me an error in "Makefile.win" that scares me) and my program exits with a return value of 3221225477. What am i doing wrong?
#include"graphics.h"
#include<math.h>
#include<conio.h>
#include<iostream>
using namespace std;
int main() {
initwindow(800,600);
int x,y;
line(0,300,getmaxx(),300);
line(400,0,400,getmaxy());
float pi=3.14159;
for(int i=-360;i<=360;i++){
x=(int)400+i;
y=(int)300-sin(i*pi/100)*25;
putpixel(x,y,WHITE);
}
getch();
closegraph();
return 0;
}
According to your issue and exit-code, the return value in hex is 0xC0000005 or STATUS_ACCESS_VIOLATION. But most developers didn't even bother to learn out-dated legacy API and I can not help you to find the exact line (use debugger, it shows you the exact line, still not the reason).
But to answer your question in the title, well, according to what free framework one uses (Qt or XWidget), the method differs, for Qt (which I would recommend) simply override paint-event and use QPainter renderer to show your QPath data.
Don't reinvent the wheel (or render-system in this case), your course and/or book may soon introduce you to one of the mentioned frameworks.

Using sqlite3_load_extension with a windows DLL

Can anyone tell me where I'm going wrong here?
I'm using C++ bulder 10.2 (clang compiler). From IDE menu I've selected File|New|Dynamic Link Library and chosen compile as C with no dependencies. I've then added sqliteFcts.c and made the sqliteFcts.dll library. It all compiles fine.
Contents of sqliteFcts.c.
#include <sqlite3ext.h>
SQLITE_EXTENSION_INIT1
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_sqliteFcts_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
return rc;
}
// My code is above. Code below was created by the IDE
#pragma argsused
int _libmain(unsigned long reason)
{
return 1;
}
From my own app I try to use the dll with the following code
int rc;
sqlite3_db_config(db,SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION,1,&rc);
rc=sqlite3_load_extension(db,"C:/temp/sqliteFcts.dll",0,&buf);
I get the error message "The specified procedure could not be found". From what I've read windows expects _libmain to be the Entry Point but sqlite expects sqlite3_sqliteFcts_init to b e the Entry Point and I've no idea how to resolve that or if that is even the problem.
I finally got it working but with a loose end.
Firstly in this line
rc=sqlite3_load_extension(db,"C:/temp/sqliteFcts.dll",0,&buf);
I supplied a null for the 3rd parameter (the entry point) thinking sqlite would resolve this however sqlite would've supplied sqlite3_sqlitefcts_init (note lower case f) as the entry point so, inevitably, the function wouldn't be found. The line should read
rc=sqlite3_load_extension(db,"C:/temp/sqliteFcts.dll","sqlite3_sqliteFcts_init",&buf);
That said, it still didn't work. After advice I received on the sqlite forum I downloaded Dependency Walker and found the function listed as _sqlite3_sqliteFcts_init (note opening underscore) although I've no idea why. Anyway, I changed the above line to
rc=sqlite3_load_extension(db,"C:/temp/sqliteFcts.dll","_sqlite3_sqliteFcts_init",&buf);
and it worked. That was for a 32 bit implementation. I later discovered that when it was compiled as a 64 bit app the opening underscore wasn't required. If anyone can throw any light on this quirk I'd be grateful.

Qlist<QCameraInfo> causes access violation in QList destructor

I am writing a video grabbing application in c++ using Qt5. I am following their example code and looking at the documentation for getting the camera info:
http://doc.qt.io/qt-5/qcamerainfo.html
The problem I have is that after I use the prescribed technique for getting camera data (which works perfectly):
QList<QCameraInfo>cameraInfos = QCameraInfo::availableCameras();
I get an Access violation error whenever cameraInfos goes out of scope.
For example, if I do:
void readDeviceInfo(void) {
// Camera devices:
QList<QCameraInfo>cameraInfos = QCameraInfo::availableCameras()
for (QList<QCameraInfo>::Iterator it = cameraInfos.begin();
it != cameraInfos.end(); ++it)
std::cout << it->description().toStdString().c_str() << std::endl;
}
The crash occurs on the return of this function. If I do:
foreach(const QCameraInfo &ci, QCameraInfo::availableCameras());
The crash occurs in the evaluation of the foreach loop. Likewise, if I declare QList<QCameraInfo> cameraInfos as a field in a class, the crash happens when the class is destroyed. This is verified by the output of my call stack:
ntdll.dll!000000007750eef1() Unknown
kernel32.dll!00000000773c1a0a() Unknown
> VideoCapture.exe!free(void * pBlock) Line 51 C
VideoCapture.exe!QCameraInfo::`scalar deleting destructor'(unsigned int) C++
VideoCapture.exe!QList<QCameraInfo>::node_destruct(QList<QCameraInfo>::Node * from, QList<QCameraInfo>::Node * to) Line 484 C++
VideoCapture.exe!QList<QCameraInfo>::dealloc(QListData::Data * data) Line 857 C++
VideoCapture.exe!QList<QCameraInfo>::~QList<QCameraInfo>() Line 817 C++
I am using Visual Studio 2013 (windows obviously).
You need to compile Qt yourself, then run your test case under a debugger and see where it crashes. You also need a minimal, self-contained test case for this - and that must be the part of the question (SSCCE). As it is, it's more likely that you're corrupting memory elsewhere and the failure you're seeing is the outcome of a corrupted heap, not a Qt bug.
Sidebar: You need to be proficient in running small examples in Qt Creator. Arguably, the templates Qt Creator comes with aren't very good for that. You can use this template, available as Other Projects->Simple qmake, to make quick prototypes.
The following works fine for me with 1 camera on current Qt on both OS X 10.9 and Windows 10/VS 2015. The std::cout you're using is red herring, you can use qDebug() as well.
// https://github.com/KubaO/stackoverflown/tree/master/questions/camlist-37603946
#include <QtWidgets>
#include <QtMultimedia>
int main(int argc, char ** argv) {
QApplication app{argc, argv};
QComboBox combo;
QObject::connect(&combo, &QComboBox::currentTextChanged, [&]{
std::cout << combo.currentText().toStdString() << std::endl;
});
for (auto const & info : QCameraInfo::availableCameras())
combo.addItem(info.description());
combo.show();
return app.exec();
}
So after following Kuba's advice and running his test program in my environment with a freshly built Qt library, I got the same errors. Then I had the bright idea to run it in release mode rather than debug. Lo and behold, it worked perfectly, with both the freshly built Qt5 (x86, as it happened) and the pre-built binaries (64 bit) gotten from Qt's downloads page.
It seems that linking to the qt debug libraries was causing this behavior. I'm now linking to the non-debug libraries in debug mode and am nice and happy -- for the most part -- I am still a little annoyed that the qt libs suffixed with 'd' don't seem to work properly on my system. Nevertheless, I can move on with developing this project.
Thanks to all that commented and answered!

Inputting values from .mat file to array in C++

I am trying to copy a 1100x1100 matrix from a .mat file to an array variable of type float in C++. I read online and found that the matio library is a good option. I installed their library using "make" on Ubuntu 12.04 (I followed the method given on their webpage).
However, I am unable to write code using it mainly because I am new to C++. I am using g++ to compile the file. I get errors such as "unknown reference to Mat_Open" and so on.
I did find this bit of code on the webpage:
#include <stdlib.h>
#include <stdio.h>
#include "matio.h"
int main(int argc,char **argv)
{
mat_t *matfp;
matvar_t *matvar;
matfp = Mat_Open(argv[1],MAT_ACC_RDONLY); //here argv[1] is "a.mat"?
if ( NULL == matfp )
{
fprintf(stderr,"Error opening MAT file %s0,argv[1]);
return EXIT_FAILURE;
}
matvar = Mat_VarReadInfo(matfp,"x"); // x is the variable we are trying to access?
if ( NULL == matvar )
{
fprintf(stderr,"Variable ’x’ not found, or error reading MAT file\n");
}
I have a couple of questions:
here, argv[1] corresponds to the .mat file I am trying to open right?
x in this code is the variable present in the .mat file I am trying to copy?
When I ran this code, I received errors stating - Unknown reference to Mat_Open and so on. Another couple of the same type of errors also were there.
I compiled this using : g++ abc.cpp -o test. (Followed by ./test. But I never got around to that due to the errors obtained during compilation).
How can I make it work? Is there any mistake with the code I used? Or with the compile statement I am using-maybe there are some linkers I need to use for compilation.
Thank you. Please remember that I am new to C++. Any advice would be helpful.
1) argv[1] - is a first parameter you put after your program call. If you want to "feel it", use debugger or code like this:
#include <iostream>
for (unsigned i = 0; i < argc; ++i)
{
std::cout << argv[i] << std::endl;
}
2) Yes, looking at http://libmatio.sourcearchive.com/documentation/1.3.4/group__MAT_g4c8205ff25c5b688a40775fbb1840b7e.html I can say, that you will read variable with name "x".
3) "undefined reference" means you need to build with matio libraries. Add something like "-lLibraryName" to your compile string. And it will have to be built.
To avoid many problems, try to install Code::Blocks, it's cross-platform and quite easy to start using C++ if you never did it before. It also supports debuggers, so you will avoid many problems quite easy.

C/C++ Allegro program wont run

wont load my picture
my default error message which is"error loading picture.bmp" pops up every time and wont run
#include "allegro.h"
int main(void)
{
char*filename="picture.bmp";
BITMAP*image;
int ret;
allegro_init();
install_keyboard();
set_color_depth(32);
ret=set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
if(ret!=0)
{
allegro_message(allegro_error);
return 1;
}
image=load_bitmap(filename,NULL);
if(!image)
{
allegro_message("error loading %s",filename);
return 1;
}
blit(image,screen,0,0,0,0,SCREEN_W,SCREEN_H);
destroy_bitmap(image);
textprintf_ex(screen,font,0,0,1,-1,"%dx%d",SCREEN_W,SCREEN_H);
while(!keypressed());
allegro_exit();
return 0;
}
END_OF_MAIN()
You're going to need to provide some more information...
What platform are you using? (MS Visual C++? Linux? Mac?...)
Which version of Allegro? (I'm guessing 4.x)
Assuming your question is, "How do I get my Allegro program to display my bitmap as intended," try to
Make sure the resulting executable file and picture.bmp are in the same directory. My guess is you are using some type of Microsoft IDE on Windows and you are trying to run the program from within the IDE (like via the debug menu or pressing F5) The resulting executable is put in a special output directory. It can't find your picture.bmp file.
Alternatively, you can try providing the full path to your picture.bmp file. You should only use this method to see if this is indeed the problem, though.
I believe your program might not be able to locate the bitmap image you are attempting to load. Try inserting the exact path to your bitmap in your code.
For example:
char*filename="C:\My Documents\Pictures\picture.bmp";