Stack around the variable 'keypoints' was corrupted - stack

I am using the following part code to get surf features plotted:
I am using the following part code to get surf features plotted:
#include<iostream>
using namespace std;
#include<vector>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
using namespace cv;
int main(int argc,char** argv)
{
VideoCapture vid(0);
if (!vid.isOpened())
{
cout<<"Camera not present..Halting the system";
return -1;
}
namedWindow("Camera_Inp",1);
namedWindow("Surfout",1);
Mat camcap,surfimg;
Mat grayimg;
SurfFeatureDetector featureimg(1000);
vector<KeyPoint>keypoints;
while(vid.isOpened()==true)
{
vid>>camcap;
imshow("Camera_Inp",camcap);
cvtColor(camcap,grayimg,CV_RGB2GRAY);
featureimg.detect(grayimg,keypoints);
drawKeypoints(grayimg,keypoints,surfimg,Scalar(255,255,255),0);
imshow("Surfout",surfimg);
if (waitKey(30)>=0)return -1;
}
return -1;
}
Visual Studio gives me the following error:
Stack around the variable 'keypoints' was corrupted.
The visual Studio debugger gives the error that:
Stack around the variable 'keypoints' was corrupted
Any help!!

Related

How to track object using dlib(c++) from video stream passed from darknet(c)?

I am using darknet to detect objects from live video stream and want to pass each frame to dlib for tracking that object but i'm confused that how i pass frames from darknet's demo.c to dlib and do the tracking.
Do i need to use c c++ connector ? if yes, how? any explanation or clues would be helpful.
thanks...
Dlib file where i want to pass ipl image and want to track the object.
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/dir_nav.h>
#include "dlib/opencv.h"
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace dlib;
using namespace std;
extern "C"{
int enx = 203, int eny = 190, int enw = 98, int enh = 86;
void track(IplImage * ipl, int enx, int eny, int enw, int enh)
{
Mat frame = cvarrToMat(ipl);
image_window win;
correlation_tracker tracker;
array2d<rgb_pixel> img;
std::cout << "Starting" << std::endl;
assign_image(img, cv_image<bgr_pixel>(frame));
tracker.start_track(img, centered_rect(point(enx, eny), enw, enh));
win.set_image(img);
win.clear_overlay();
win.add_overlay(tracker.get_position());
while(ipl) {
Mat frame = cvarrToMat(ipl);
assign_image(img, cv_image<bgr_pixel>(frame));
tracker.update(img);
win.set_image(img);
win.clear_overlay();
win.add_overlay(tracker.get_position());
}
}
}
I would recommend you to look at https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp
where you will find many ideas about darknet data manipulation. Including tracker

Opencv : No error in code , but webcam not showing in result

I am training out the tutorial in opencv.
it had no error when compile.
I know the code for the tutorial is for opencv2.4 and I had change the coding for cvquery and videoframe.
My output is like this
.
My webcam is working fine but it not showing anything in my result.
If you wish to perform face detection using HaarCascades, you can use this code:
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
CascadeClassifier facecascade;
int main()
{
Mat frame;
facecascade.load("haarcascade_frontalface_alt.xml");
if(facecascade.empty())
{
cout<<"Error";
}
VideoCapture cap(0);
int i=0,j=0,k=0;
while(1)
{
cap>>frame;
Mat frame_gray;
cvtColor(frame,frame_gray,CV_BGR2GRAY);
vector<Rect>faces;
facecascade.detectMultiScale(frame_gray,faces,1.1,2,0|CV_HAAR_SCALE_IMAGE,Size(70,70));
if(faces.size()>0)
{
for(i=0;i<faces.size();i++)
{
rectangle(frame_gray,faces[i],Scalar(200,200,250),2,8,0);
}
char no[5];
sprintf(no,"No. of faces detected = %d",int(faces.size()));
putText(frame_gray,no,Point(10,30),FONT_HERSHEY_TRIPLEX,1,Scalar(255,255,255),1);
imshow("out",frame_gray);
char c= waitKey(5);
if(c=='b')
break;
}
return 0;
}

cvResize identifier is undefined

All my OpenCV functions are working perfectly fine. But cvResize() is not found by the compiler. I guess this function is not installed during installation.
The following program tells me the error that cvResize identifier is undefined
Is it possible to download this function separately and use it? How?
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <ctype.h>
#include <iostream>
using namespace std;
int main( int argc, char** argv )
{
// Create an IplImage object *image
IplImage *source = cvLoadImage( argv[1]);
// Here we retrieve a percentage value to a integer
int percent = atoi(argv[3]);
// declare a destination IplImage object with correct size, depth and channels
IplImage *destination = cvCreateImage
( cvSize((int)((source->width*percent)/100) , (int)((source->height*percent)/100) ), source->depth, source->nChannels );
//use cvResize to resize source to a destination image
cvResize(source, destination);
// save image with a name supplied with a second argument
cvSaveImage( argv[2], destination );
return 0;
}
You are missing an include:
#include "opencv2/imgproc/imgproc_c.h"
I fixed the error by
#import <opencv2/imgproc/imgproc_c.h>

OpenCV 2.4.2 imshow causes crash

I have this nasty problem with opencv 2.4.2.
I use VS 2012 to compile this short test programm.
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace cv;
int main()
{
Mat sudoku = imread("sudoku.jpg",0);
namedWindow("Lines", CV_WINDOW_AUTOSIZE);
imshow("Lines", sudoku);
}
Imshow is the problem. When I remove it, it runs without any problem. I found a tip here which said to use debug libs instead but it didn't help.
First of all, you have to check if image is loaded correctly. To do this just check if image.data is NULL or not.
Secondly, after calling imshow you have to call waitKey to show image:
http://opencv.willowgarage.com/documentation/cpp/user_interface.html#cv-waitkey
Here's the whole code:
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat sudoku = imread("sudoku.jpg",0);
if (sudoku.data == NULL)
{
cout << "No image found! Check path." << endl;
return 1;//ERROR
}
else
{
namedWindow("Lines", CV_WINDOW_AUTOSIZE);
imshow("Lines", sudoku);
waitKey();//without this image won't be shown
return 0;//OK
}
}

Lua does not load libs

I decided to add scripting with Lua. I've downloaded and compiled interpreter. It works fine, but when I want to use any functions from os.* or string.* libs, it says, that "attemt to index global 'os' (a nil value)"
Here is my code and should work, but it does not:
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
extern "C" {
#include "..\liblua\lua.h"
#include "..\liblua\lualib.h"
#include "..\liblua\lauxlib.h"
}
int main(int argc, TCHAR* argv[])
{
lua_State *LuaVM = luaL_newstate();
lua_pushcfunction(LuaVM,luaopen_base);
lua_call(LuaVM,0,0);
lua_pushcfunction(LuaVM,luaopen_math);
lua_call(LuaVM,0,0);
lua_pushcfunction(LuaVM,luaopen_string);
lua_call(LuaVM,0,0);
lua_pushcfunction(LuaVM,luaopen_table);
lua_call(LuaVM,0,0);
int error;
lua_pushstring(LuaVM,"Ver 0.525.5");
lua_setglobal(LuaVM,"Version");
while (true)
{
string strCode;
getline(cin,strCode);
error = luaL_loadbuffer(LuaVM,strCode.c_str(),strCode.length(),"") ||
lua_pcall(LuaVM,0,0,0);
if (error)
{
cout<< lua_tostring(LuaVM,-1)<<endl;
lua_pop(LuaVM,1);
}
}
lua_close(LuaVM);
return 0;
}
What's wrong with it?
In Lua 5.2 the standard luaopen_* functions do not set the corresponding global variables.
Why not copy and adapt the code in linit.c or just call luaL_openlibs?
Otherwise, do what they do: call luaL_requiref for each luaopen_* function.
See http://www.lua.org/source/5.2/linit.c.html#luaL_openlibs.

Resources