Trying to create a function which will fill a vector of objects with initialized objects. Please help. ERROR: Segmentation fault (core dumped)
EDIT:
Ok so, problem seems to be occurring in the line when trying to access OBJ[0].age.
Also forgot the Point2d function comes from OpenCV libraries which I forgor to add, but they dont seem to contribute to the error in any way.
#include <iostream>
#include <vector>
struct objtracker
{
int age;
vector<int> frID;
vector<Point2d> cent;
objtracker()
{
age = 1;
}
~objtracker()
{
// Destroy ObjectTracker
}
};
vector<objtracker> OBJ;
void create_new_tracker(vector<objtracker> OBJ,Point2d cent,int frameID,objtracker O){
O.cent.push_back(cent);
O.frID.push_back(frameID);
}
int main(){
Mat Y;
Y = imread("hor.jpeg",CV_LOAD_IMAGE_COLOR);
Point2d J;
J.x = 100;
J.y = 100;
int frameID = 100;
objtracker O;
create_new_tracker(OBJ,J,frameID,O);
create_new_tracker(OBJ,J,frameID,O);
create_new_tracker(OBJ,J,frameID,O);
create_new_tracker(OBJ,J,frameID,O);
create_new_tracker(OBJ,J,frameID,O);
cout<<OBJ[0].age<<"\n";
return 1; }