Access violation using flann matcher - c++

I'm facing a very annoying problem when I create an object of FalnnBaseMatcher.
The code is the following and it worked fine on ubuntu under eclipse.
#include <iostream>
#include "C:\openCv\opencv\build\include\opencv2\core\core.hpp"
#include "C:\openCv\opencv\build\include\opencv2\highgui\highgui.hpp"
#include "C:\openCv\opencv\build\include\opencv2\imgproc\imgproc.hpp"
#include "C:\openCv\opencv\build\include\opencv2\features2d\features2d.hpp"
#include "C:\openCv\opencv\build\include\opencv2\nonfree\nonfree.hpp"
using namespace std;
using namespace cv;
int main(){
cv::VideoCapture cap("video2.mp4");
if(!cap.isOpened()){ // check if we succeeded
return -1;
}
Mat frame; // creates the object frame
FlannBasedMatcher matcher; //create object matcher
return 0;
}
it compiles but when i run i got an access violation. I tried to split the problem and i figured out that i have this error when i create the object FlannBasedMatcher matcher;
Any help is accepted, thank you very much.
I'm using visual studio express edition 2012 and opencv 242 under windows 7.
Now modifying slightly the code I get an interuption in free.c
/***
*free.c - free an entry in the heap
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Defines the following functions:
* free() - free a memory block in the heap
*
*******************************************************************************/
#include <cruntime.h>
#include <malloc.h>
#include <winheap.h>
#include <windows.h>
#include <internal.h>
#include <mtdll.h>
#include <dbgint.h>
#include <rtcsup.h>
/***
*void free(pblock) - free a block in the heap
*
*Purpose:
* Free a memory block in the heap.
*
* Special ANSI Requirements:
*
* (1) free(NULL) is benign.
*
*Entry:
* void *pblock - pointer to a memory block in the heap
*
*Return:
* <void>
*
*******************************************************************************/
void __cdecl _free_base (void * pBlock)
{
int retval = 0;
if (pBlock == NULL)
return;
RTCCALLBACK(_RTC_Free_hook, (pBlock, 0));
retval = HeapFree(_crtheap, 0, pBlock);
if (retval == 0)
{
errno = _get_errno_from_oserr(GetLastError());
}
}
The interruption is in: if (retval == 0)
SOLVED!
I rebuilt openCv for VisualStudio 2012 using cMake and now works fine.

Related

Trying to access UWP's EmailMessage class from C++ results in "REGDB_E_CLASSNOTREG Class not registered" error

My goal is to use EmailMessage class to let users of my desktop app interact with the Windows Mail app on Windows 10. As a test I'm trying the following from a stock C++ console app in Visual Studio 2017:
#include <Windows.h>
#include <roapi.h>
#pragma comment(lib, "runtimeobject.lib")
#include <Windows.Services.Store.h>
#include <wrl.h>
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Services::Store;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::System;
using namespace ABI::Windows::Foundation::Collections;
using namespace ABI::Windows::ApplicationModel::Email;
HRESULT hr;
if(SUCCEEDED(hr = RoInitialize(RO_INIT_MULTITHREADED)))
{
ComPtr<IEmailMessage> pEmlMsg;
hr = RoGetActivationFactory(HStringReference(L"Windows.ApplicationModel.Email").Get(), __uuidof(pEmlMsg), &pEmlMsg);
if (SUCCEEDED(hr) &&
pEmlMsg)
{
//... keep going
}
else
wprintf(L"ERROR: 0x%x RoGetActivationFactory\n", hr);
RoUninitialize();
}
But my RoGetActivationFactory call above always returns REGDB_E_CLASSNOTREG Class not registered.
Any idea what am I missing there?
PS. I'm testing it on Windows 10 v.1903 build 18362.239.
you got REGDB_E_CLASSNOTREG Class not registered because "Windows.ApplicationModel.Email" really not registered. ( look under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId key - no Windows.ApplicationModel.Email subkey here )
you have 2 errors in code, instead self string "Windows.ApplicationModel.Email" - you need use RuntimeClass_* strings defined in some winrt header file. you need use
RuntimeClass_Windows_ApplicationModel_Email_EmailMessage
which is declared in Windows.ApplicationModel.email.h
then RoGetActivationFactory can not return IEmailMessage direct. it can return IActivationFactory interface (You can get an IActivationFactory pointer by calling the RoGetActivationFactory function. ) and then you need call IActivationFactory::ActivateInstance for get pointer to IInspectable and finally QueryInterface on it for get IEmailMessage
so better (if you need single instance of IEmailMessage) use RoActivateInstance here. code can be next
#include <winstring.h>
#include <roapi.h>
#include <Windows.ApplicationModel.email.h>
void CALLBACK ep(void*)
{
if (0 <= RoInitialize(RO_INIT_MULTITHREADED))
{
HSTRING_HEADER hsh;
HSTRING activatableClassId;
IInspectable* instance;
ABI::Windows::ApplicationModel::Email::IEmailMessage* pEmlMsg;
WindowsCreateStringReference(RuntimeClass_Windows_ApplicationModel_Email_EmailMessage,
_countof(RuntimeClass_Windows_ApplicationModel_Email_EmailMessage) - 1,
&hsh, &activatableClassId);
if (0 <= RoActivateInstance(activatableClassId, &instance))
{
HRESULT hr = instance->QueryInterface(IID_PPV_ARGS(&pEmlMsg));
instance->Release();
if (0 <= hr)
{
//...
// some demo usage
static const WCHAR body[] = L"-- demo --";
WindowsCreateStringReference(body, _countof(body) - 1, &hsh,
&activatableClassId);
if (0 <= pEmlMsg->put_Body(activatableClassId))
{
if (0 <= pEmlMsg->get_Body(&activatableClassId))
{
DbgPrint("%S\n",
WindowsGetStringRawBuffer(activatableClassId, 0));
WindowsDeleteString(activatableClassId);
}
}
pEmlMsg->Release();
}
}
RoUninitialize();
}
//...
}

error: no matching function for call to 'FaceDetector::FaceDetector(std::__cxx11::string)'

I am new to C++ and i am getting error like
error: no matching function for call to 'FaceDetector::FaceDetector(std::__cxx11::string)'
FaceDetector fd(string(DEFAULT_CASCADE_PATH));
and i am attaching my code and error log how to fix this please guide me
#define DEFAULT_CASCADE_PATH "cascades/haarcascade_frontalface_default.xml"
#define ORIGINALS_LIST "obama_raw/list"
#define OUTPUT_DIR "obama_faces"
#define OUTPUT_LIST "list"
#define FACE_SIZE Size(150,150)
#include <cstdlib>
#include <fstream>
#include "cv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "FaceDetector.h"
using namespace std;
using namespace cv;
void read_input_list(const string &list_path, vector<Mat> &images) {
ifstream file(list_path.c_str());
string path;
while (getline(file, path)) {
images.push_back(imread(path));
}
}
int main(int argc, char** argv) {
FaceDetector fd(string(DEFAULT_CASCADE_PATH));
vector<Mat> raw_faces;
ofstream out_list(format("%s/%s", OUTPUT_DIR, OUTPUT_LIST).c_str());
read_input_list(string(ORIGINALS_LIST), raw_faces);
int img_c = 0; //images counter
//now detect the faces in each of the raw images:
for (vector<Mat>::const_iterator raw_img = raw_faces.begin() ; raw_img != raw_faces.end() ; raw_img++){
vector<Rect> faces;
//detect faces in the image (there should be only one):
fd.findFacesInImage(*raw_img, faces);
//cut each face and write to disk:
for (vector<Rect>::const_iterator face = faces.begin() ; face != faces.end() ; face++){
int edge_size = max(face->width, face->height);
Rect square(face->x, face->y, edge_size, edge_size);
Mat face_img = (*raw_img)(square);
//resize:
resize(face_img, face_img, FACE_SIZE);
//write to disk:
string face_path = format("%s/%d.jpg", OUTPUT_DIR, img_c++);
imwrite(face_path,face_img);
out_list << face_path << endl;
}
}
out_list.close();
return 0;
}
and i am attaching my error log.Please can any one help.
Thanks in advance
Error : https://i.stack.imgur.com/RZXXK.jpg
From GCC 5, A new ABI is enabled by default. In that new ABI, std::__cxx11 namesapce was introduced.
According to your error message, It seems that your program and OpenCV library you want to link with were build with different GCC version, which made incompatible binary.
For more information, you can read the following page:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

how to caputre video from usb camera in MJPEG pixel format

i working in stereo cameras project (connect two usb cameras to my laptop) but the proplem is my web cameras format are "YUYV" and this format did't support that to run two cameras togther so how i do that ? that's my code in c++ and opencv3
#include <opencv2/opencv.hpp>
/**
* #file main.cpp
* #brief OpenCV Stereo Webcam.
* #author Martin Peris (http://www.martinperis.com)
* #date 21/08/2011
*/
/*
main.cpp - Implement a simple stereo webcam with OpenCV and C++
Copyright (c) 2011 Martin Peris (http://www.martinperis.com).
All right reserved.
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this application; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//This works for me on OpenCV 2.0 with 2 Logicool webcams.
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>
#include <iostream>
#include <sstream>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/video/background_segm.hpp>
#include "cv.h"
#include "highgui.h"
#include <iostream>
//Maybe in OpenCV2.2 the correct include statement would be:
//#include "opencv2/opencv.hpp"
int main(int, char**)
{
cv::VideoCapture capLeft(4); // open the Left camera
cv::VideoCapture capRight(2); // open the Right camera
if(!capLeft.isOpened() || !capRight.isOpened()) // check if we succeeded
{
std::cerr << "ERROR: Could not open cameras." << std::endl;
return -1;
}
capLeft.set(CV_CAP_PROP_FPS, 25);
capRight.set(CV_CAP_PROP_FPS, 25);
// Values taken from output of Version 1 and used to setup the exact same parameters with the exact same values!
capLeft.set(CV_CAP_PROP_FRAME_WIDTH, 320);
capLeft.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
capRight.set(CV_CAP_PROP_FRAME_WIDTH, 320);
capRight.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
cv::namedWindow("Left",1);
cv::namedWindow("Right",1);
for(;;)
{
bool isValid = true;
cv::Mat frameLeft;
cv::Mat frameRight;
try
{
capLeft >> frameLeft; // get a new frame from left camera
capRight >> frameRight; //get a new frame from right camera
}
catch( cv::Exception& e )
{
std::cout << "An exception occurred. Ignoring frame. " << e.err << std::endl;
isValid = false;
}
if (isValid)
{
try
{
cv::imshow("Left", frameLeft);
cv::imshow("Right", frameRight);
/************************************************************
* This is the place for all the cool stuff that you *
* want to do with your stereo images *
************************************************************/
//TODO:...
}
catch( cv::Exception& e )
{
/************************************************************
* Sometimes an "Unrecognized or unsuported array type" *
* exception is received so we handle it to avoid dying *
************************************************************/
std::cout << "An exception occurred. Ignoring frame. " << e.err << std::endl;
}
}
if(cv::waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}

OpenCV FeatureDetector is not initialized

I am trying to create a class where I shall find KeyPoints in an image. However, I get a ridiculous error I cannot figure out how to solve.
The problem is now that
this->detector
is zero, so it is for some reason not initialized properly. I have searched on google but I haven't found anything.
My headerfile looks as follows
/*
* FindKeyPoints.h
*
* Created on: Jan 21, 2015
* Author: erikbylow
*/
#ifndef FINDKEYPOINTS_H_
#define FINDKEYPOINTS_H_
#include <vector>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
using namespace std;
class FindKeyPoints {
private:
// Create vector of KeyPoints to store the detected keypoint in
vector<cv::KeyPoint> keyPointsOld;
vector<cv::KeyPoint> keyPointsNew;
// Threshold for similarity
const int THRESHOLD = 10;
// Instance(?) DescriptionExtractor and descriptor
cv::Ptr<cv::DescriptorExtractor> descriptionExtractor;
cv::Ptr<cv::FeatureDetector> detector;
public:
FindKeyPoints(const string &METHOD);
virtual ~FindKeyPoints();
void detectKeypoints(cv::Mat& imgNew, cv::Mat& imgOld);
};
#endif /* FINDKEYPOINTS_H_ */
And constructor looks as
FindKeyPoints::FindKeyPoints(const string &METHOD) {
cout<<METHOD<<endl;
cv::initModule_features2d();
this->detector = cv::FeatureDetector::create("SURF");
//this->descriptionExtractor = cv::DescriptorExtractor::create(METHOD);
}
and a function I will use looks as:
// Input: The new image and the old image. Find Keypoints and extract the descriptors.
void FindKeyPoints::detectKeypoints(cv::Mat& imgNew,
cv::Mat& imgOld) {
if (this->detector == 0){
cout<<"Hej"<<endl;
}
// this->detector->detect(imgNew, keyPointsNew);
// this->detector->detect(imgOld, keyPointsOld);
}
I use cmake and (part of) my CMakeLists.txt looks like:
TARGET_LINK_LIBRARIES(${PROJECT_NAME} groundtruth ${OpenCV_LIBS} ${QT_LIBRARIES}
${QGLViewer_LIBRARIES} ${OPENGL_gl_LIBRARY} GL
glut)
Can it be that
${OpenCV_LIBS}
does not include libopencv_nonfree.so ?
Regards
I suspect the error is that I had only included
opencv2/nonfree/features2d.hpp
and not also
opencv2/nonfree/nonfree.hpp.

trouble with Open Cv and GPIO on mini6410

I am doing a simple project on arm based mini6410. I have debian package installed on mini. My project is to interface one IR motion sensor and I USB webcam with the mini6410. the working will be simple, whenever there will be any motion detected by IR sensor, the webcam will be on for 30 seconds save the images (over write the previous) and then off.
I have already cross comiled the Open CV code using arm-linux-gcc
For IR I am using GPE register.
Here I am stuck with a issue which I am unable to resolve. and even dont know how to resolve. OpenCv code is a cpp file camera.cpp and the file which deals with I/O ports is a C file named sensor.c. Now in that c file I am polling or whatever mechanism to check if the GPE register is 1 or not. If it is one, I should start the Open CV code which will start to capture images. further more this sensor.c file is not to be compiled rather made a module and then insmod on my mini6410.
However I dont know how to write c++ code in a c file. you can say i dont know how to call the OpenCV thing from the C file. as it is a module and within this i cant write the cpp code as then using namespace std and using namespace cv doesnot work.
i am new to embedded stuff and linux it self. so I wanted to know are there some possible solutions.
i am attaching my codes of both files.
This is sensor.c
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/serio.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <mach/map.h>
#include <mach/regs-clock.h>
#include <mach/regs-gpio.h>
#include <plat/gpio-cfg.h>
#include <mach/gpio-bank-q.h>
#include <mach/gpio-bank-e.h>
#include <mach/map.h>
#include <plat/regs-timer.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/moduleparam.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>
#include <mach/gpio-bank-k.h>
#define RLV 0x0FFF
unsigned Gpe;
unsigned sensor_value;
typedef struct
{
int delay;
} TIM_DEV;
static TIM_DEV TimDev;
static irqreturn_t INTHandler(int irq,void *TimDev)
{
Gpe = readl(S3C64XX_GPEDAT);
Gpe &= ~(0xF<<1);
readl(sensor_value, S3C64XX_GPEDAT);
while (sensor_value == 1)
{//1 means that IR sensor has detected a motion and given a value of +5 V
for (i = 0; i < 30; i++){
//CV_function();
// delay here such that delay(1 s) * 30 = 30 seconds
}
}
return IRQ_HANDLED;
}
static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.write = MyWrite,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};
static int __init dev_init(void)
{
int ret;
unsigned TimerControl;
unsigned TimerINTControl;
unsigned TimerCNTB;
unsigned TimerCMPB;
unsigned TimerCFG1;
unsigned Ge;
TimerControl = readl(S3C_TCON);
TimerINTControl = readl(S3C_TINT_CSTAT);
TimerCNTB = readl(S3C_TCNTB(0));
TimerCMPB = readl(S3C_TCMPB(0));
TimerCFG1 = readl(S3C_TCFG1);
TimerCFG1 &= ~(S3C_TCFG1_MUX0_MASK);
TimerCNTB = RLV;
TimerCMPB = 0;
writel(TimerCNTB, S3C_TCNTB(0));
writel(TimerCMPB, S3C_TCMPB(0));
writel(TimerCFG1, S3C_TCFG1);
TimerControl |= S3C_TCON_T0MANUALUPD;
TimerINTControl |= S3C_TINT_CSTAT_T0INTEN;
writel(TimerControl, S3C_TCON);
writel(TimerINTControl, S3C_TINT_CSTAT);
TimerControl = readl(S3C_TCON);
TimerControl |= S3C_TCON_T0RELOAD;
TimerControl &= ~S3C_TCON_T0MANUALUPD;
TimerControl |= S3C_TCON_T0START;
writel(TimerControl, S3C_TCON);
//////////////Here I am configuring my GPE as input/////////////
Ge = readl(S3C64XX_GPECON);
Ge &= ~(0xFFFF<<4);
Ge |= (0x0000<<4);
writel(Ge, S3C64XX_GPECON);
/////////////
misc_register(&misc);
ret = request_irq(IRQ_TIMER0, INTHandler, IRQF_SHARED, DEVICE_NAME, &TimDev);
if (ret)
{
return ret;
}
return ret;
}
static void __exit dev_exit(void)
{
free_irq(IRQ_TIMER0, &TimDev);
misc_deregister(&misc);
}
module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("XYZ");
this is camera.cpp
#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;
int main( int argc, const char** argv )
{CvCapture* capture = 0;
Mat frame, frameCopy, image;
capture = cvCaptureFromCAM( 2 );
if( !capture )
{
cout << "No camera detected" << endl;
}
if( capture )
{
cout << "In capture ..." << endl;
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;
if( frame.empty() )
break;
if( iplImg->origin == IPL_ORIGIN_TL )
frame.copyTo( frameCopy );
else
flip( frame, frameCopy, 0 );
cvSaveImage("image.jpg" ,iplImg);
}
cvReleaseCapture( &capture );
return 0;
}
the for loop in the sensor.c file should have my this above code by some means
I hope you get the idea,
Thanks
The missing link in the code shown is a mechanism by which the user-space code shown above can get notification of a change in the GPIO pin detected by the device driver.
There are two obvious ways to achieve this:
Integrate the GPIO pin into the platform's GPIO resources and then use the generic sysfs mechanism from user-space. The Linux kernel GPIO documentation describes both kernel and user-space side of this.
Have your driver expose a sysfs node for the GPIO line. sysfs is fundamental to the Linux Driver Model. I suggest a thorough read of Linux Device Drivers 3rd Edition.
The user-space side of either method is similar: You open the sysfs resource exported by your module and then use either poll() or select() to block until an event occurs.