I needed to print my Mat object and the programm throws an exception... The project is really simply: creating Mat object and printing by using cout - just like in OpenCV tutorial:
#include <core/core.hpp>
#include <highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
Mat O = Mat::ones(2, 2, CV_32F);
cout << "O = " << endl << " " << O << endl << endl;
// Point2f P(5, 1);
// cout << "Point (2D) = " << P << endl << endl;
return 0;
}
The exception says: Unhandled exception at 0x59430671 (msvcp100d.dll) in printingTest.exe: 0xC0000005: Access violation reading location 0x00000000. Console shows only
O = [
Precisely it stops on "operations.hpp" at:
static inline std::ostream& operator << (std::ostream& out, const Mat& mtx) { Formatter::get()->write(out, mtx); return out; }
It seems "out" to be empty, but does someone know why? Tutorial says it should work...
I had earlier similar problem with throwing exception and I solved it here:
http://answers.opencv.org/question/5113/problem-with-reading-image-to-mat/
Is it possible that there is another environmental variable conflict? or maybe a collision 'cause I'm using VS2012 and there's OpenCV only for v10?
The thing with Point2f which is commented works normally.
Your code works fine here with VS2010. Make sure you are linking the correct libraries (release vs. debug). If this does not help try to reinstall openCV or make your own build on VS2012, preparing it with cmake, from the sources.
Related
I downloaded a webcam_face_pose_ex.cpp file from GitHub and now i want to compile and run it on my mac.
#include <dlib/opencv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <X11/Xlib.h>
using namespace dlib;
using namespace std;
int main()
{
try
{
cv::VideoCapture cap(0);
if (!cap.isOpened())
{
cerr << "Unable to connect to camera" << endl;
return 1;
}
image_window win;
// Load face detection and pose estimation models.
frontal_face_detector detector = get_frontal_face_detector();
shape_predictor pose_model;
deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;
// Grab and process frames until the main window is closed by the user.
while(!win.is_closed())
{
// Grab a frame
cv::Mat temp;
if (!cap.read(temp))
{
break;
}
// Turn OpenCV's Mat into something dlib can deal with. Note that this just
// wraps the Mat object, it doesn't copy anything. So cimg is only valid as
// long as temp is valid. Also don't do anything to temp that would cause it
// to reallocate the memory which stores the image as that will make cimg
// contain dangling pointers. This basically means you shouldn't modify temp
// while using cimg.
cv_image<bgr_pixel> cimg(temp);
// Detect faces
std::vector<rectangle> faces = detector(cimg);
// Find the pose of each face.
std::vector<full_object_detection> shapes;
for (unsigned long i = 0; i < faces.size(); ++i)
shapes.push_back(pose_model(cimg, faces[i]));
// Display it all on the screen
win.clear_overlay();
win.set_image(cimg);
win.add_overlay(render_face_detections(shapes));
}
}
catch(serialization_error& e)
{
cout << "You need dlib's default face landmarking model file to run this example." << endl;
cout << "You can get it from the following URL: " << endl;
cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
}
catch(exception& e)
{
cout << e.what() << endl;
}
}
I tried g++ webcam_face_pose_ex.cpp command but I get:
webcam_face_pose_ex.cpp:30:10: fatal error: 'dlib/opencv.h' file not found
#include <dlib/opencv.h>
^~~~~~~~~~~~~~~
1 error generated.
Was Wondering what I could do to fix this?
The Example File Is Not Meant to be Compiled Using g++
Read the following to learn a bit about the -I flag and #include statements:
The webcam_face_pose_ex.cpp is part of a larger project and you won't be able to compile it on its own because it depends on other files. The #include directive specifies that in order to compile this program, code from the file specified by #includemust be compiled first. This means the entire dlib must be downloaded before compiling webcam_face_pose_ex.cpp. This project also requires opencv2 so we can download it and place the opencv2 folder in the dlib project folder.
Now we can open terminal and change directory into the dlib project folder and compile the file using the following command:
g++ -I. examples/webcam_face_pose_ex.cpp
Note we're specifying the directory of where to find the files specified by #include using the -I parameter as -I. this means to search the current working directory for the files. There it will find the dlib folder and dlib/opencv.h.
How ever, this isn't enough. When you execute the command, you'll encounter an error opencv2/opencv_modules.hpp: No such file or directory.
Solution
The dlib project documentation states that the examples should be built using cmake. Make sure to use cmake to compile the examples.
This simple example works as expected in g++, but in MS VS 2010 or 2013 shows a runtime library debug error (Invalid allocation size) before the error is caught (clicking Ignore does then flow through the error handler showing it correctly to be a bad_alloc).
Any ideas about why VS behaves this way?
#include <iostream>
#include <exception>
using namespace std;
int main() {
int x;
cout << "Enter -1 for bad_alloc: ";
cin >> x;
try
{
int* myarray = new int[x];
}
catch (exception& e)
{
cout << "Standard exception: " << e.what() << endl;
}
return 0;
}
That's so that you can analyse the exception at the point it is thrown, before the stack is unwound.
It's a feature that the debugger does this for you.
Nothing to worry about here.
I am trying to integrate a code already written in ROS with some basic Visp lines so as to display a camera feed using Visp functions. I am a beginner in visp and hence I am trying something basic.I am attaching the relevant code lines here
//Lots of lines of code above and blow this code block
cv::Mat src_gray;
cv::cvtColor(imageLeft, src_gray, CV_RGB2GRAY );//imageLeft is a colour image got from the camera through another node
vpImage<unsigned char> I;
vpImageConvert::convert(src_gray,I) ;
vpDisplayOpenCV display;
if(this->lt == false)//this if loop is to prevent from infinite windows coming out
{display.init(I, 100, 100, "Line tracking");
this->lt = true;}
vpDisplay::display(I);
vpDisplay::flush(I);
Let me ensure you that this piece of code is in a callback and hence it is equivalent to an infinte while loop unless the process is stopped.
I am not able to get the camera output in the window.When I run the node the window opens but no image.Any ideas?
The ViSP-ROS interfece has been changing recently. While ViSP Bridge provides low level interface between ROS and ViSP, Visp ROS is a better and higher level interface. From there you can reach to this tutorial where a regular ViSP code is modified to use ROS.
The ViSP code similar to yours:
#include <visp/vp1394TwoGrabber.h>
#include <visp/vpDisplayX.h>
#include <visp/vpImage.h>
int main()
{
#ifdef VISP_HAVE_DC1394_2
try {
vpImage<unsigned char> I; // Create a gray level image container
bool reset = true; // Enable bus reset during construction (default)
vp1394TwoGrabber g(reset); // Create a grabber based on libdc1394-2.x third party lib
g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8);
g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_60);
g.open(I);
std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;
#ifdef VISP_HAVE_X11
vpDisplayX d(I);
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
while(1) {
g.acquire(I);
vpDisplay::display(I);
vpDisplay::flush(I);
if (vpDisplay::getClick(I, false))
break;
}
}
catch(vpException e) {
std::cout << "Catch an exception: " << e << std::endl;
}
#endif
}
And the ROS enabled code:
#include <visp/vpDisplayX.h>
#include <visp/vpImage.h>
#include <visp_ros/vpROSGrabber.h>
int main()
{
try {
//vpImage<unsigned char> I; // Create a gray level image container
vpImage<vpRGBa> I; // Create a color image container
vpROSGrabber g; // Create a grabber based on ROS
g.setCameraInfoTopic("/camera/camera_info");
g.setImageTopic("/camera/image_raw");
g.setRectify(true);
g.open(I);
std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;
#ifdef VISP_HAVE_X11
vpDisplayX d(I);
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
while(1) {
g.acquire(I);
vpDisplay::display(I);
vpDisplay::flush(I);
if (vpDisplay::getClick(I, false))
break;
}
}
catch(vpException e) {
std::cout << "Catch an exception: " << e << std::endl;
}
}
Hope this helps!
I'm trying to create a CGI script that will take a picture and save it to the location I give it. I'm using the Raspberry Pi and the Pi camera module with the uv4l driver. I have also chosen to use Apache2.
Currently the script runs with no errors given and no errors in the Apache error log, but the image doesn't get saved. The camera does open because the red light appears on it. I also check to see if the image is empty which it isn't.
So far I have tried changing folder permissions so that the user pi owns everything. I have also tried to save over an already existing file but it never gets updated. I have never used Apache2 or CGI scripting before so I feel that the problem lies in there but I'm not entirely sure what to search because I am getting no errors. Any suggestions would be greatly appreciated.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv){
cv::VideoCapture cap(-1);
if (!cap.isOpened()){
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>";
cout << "<h1> Camera didn't open </h1>";
cout << "</html>";
return -1;
}
//cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
//cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
int count = 40;
cv::Mat frame;
bool bSuccess = cap.read(frame);
while (count != 0){
count--;
}
if (!bSuccess){
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>";
cout << "<h1> Photo did't work get read in</h1>";
cout << "</html>";
return 0;
}
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>";
cout << "<h1> Photo Taken + Saved</h1>";
cout << "</html>";
cv::imwrite("/var/www/photos/Current.png", frame);
return 0;
}
I'm using this command to compile:
g++ -lopencv_core -lopencv_highgui -L/usr/lib/uv4l/uv4lext/armv6l -luv4lext -Wl,- rpath,'/usr/lib/uv4l/uv4lext/armv6l' time.cpp -o test_script.cgi
I fixed my own problem. The method imwrite() was saving over an already existing image without write permissions.
I have succesfully linked my basic project containing only one ReadPc.cpp file obviously reading point cloud from file in Visual Studio 2010
After running exception is thrown and pop up window "R6010 abort() has been called" is shown
When i was setting up my application i followed this tutorial
Here is my code
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int
main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
std::cout << "bejzikl";
if (pcl::io::loadPCDFile<pcl::PointXYZ> ("kitchen.pcd", *cloud) == -1) //* load the file
{
PCL_ERROR ("Couldn't read file test_pcd.pcd \n");
return (-1);
}
std::cout << "Loaded "
<< cloud->width * cloud->height
<< " data points from test_pcd.pcd with the following fields: "
<< std::endl;
for (size_t i = 0; i < cloud->points.size (); ++i)
std::cout << " " << cloud->points[i].x
<< " " << cloud->points[i].y
<< " " << cloud->points[i].z << std::endl;
return (0);
}
Problem line seems to be this one
if (pcl::io::loadPCDFile ("kitchen.pcd", *cloud) == -1)
In debug mode Output says
First-chance exception at 0x7566812f in Meshes.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0030f36c..
Unhandled exception at 0x7566812f in Meshes.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0030f36c..
The program '[15424] Meshes.exe: Native' has exited with code -529697949 (0xe06d7363).
I appreciate any advice
In my case, this is due to difference in the configuration of dependencies and the configuration of the project. Solved by changing the configuration to Release mode as my project dependencies are in release mode.
I don't have experience with PCL library but std::bad_alloc, means that new failed.
"Type of the exceptions thrown by the standard definitions of operator new and operator new[] when they fail to allocate the requested storage space."
source: cplusplus
Maybe the file you are loading is too big, or if that load is requesting continues memory you don't have it available.
Also you can try to catch exception and see what ex.what() will suggest about exception cause.
If you are using the "kitchen.pcd" from the tutorials of the PCL site or github, then you should know that the points of this file is of type .
you can open the ".pcd" file in wordpad and make sure of this.
If so, change the types "PointXYZ" to "PointXYZRGB".
Hope it would be helpful!