Ask Your Question
0

Assertion failed.How can I solve

asked 2016-08-20 04:29:08 -0500

ramasamy-rudram gravatar image

updated 2016-08-20 07:09:06 -0500

berak gravatar image

I used OpenCV2.4.13 and I got OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1DataType<_Tp>::channels) < (unsigned)(size.p[1]channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file D:\Ram\Software\OpenCV2.4.13\opencv\build\include\opencv2/core/mat.hpp, line 538

while trying to compile the below piece of code.

                myfile << shape.part(i);
                //std::string num = std::to_string(shape.part(i));
                for (int i = 0; i < 68; i++)
                {
                    myfile << shape.part(i);
                    /*fwrite(num, 40, 1, fp);*/

                }

How can I solve it.

edit retag flag offensive close merge delete

Comments

let's reopen it, if there's some more context.

berak gravatar imageberak ( 2016-08-20 05:24:39 -0500 )edit

your code does not touch any cv::Mat. are you sure, you got the correct code snippet there ?

berak gravatar imageberak ( 2016-08-20 07:07:37 -0500 )edit

CvPoint P1; P1.x = 200; P1.y = 417;

        cv::Mat image;
        image.at<cv::Vec3b>(P1.y, P1.x);

        image.at<cv::Vec3b>(P1.y, P1.x)[0] = 140;
        image.at<cv::Vec3b>(P1.y, P1.x)[1] = 160;
        image.at<cv::Vec3b>(P1.y, P1.x)[2] = 160;
ramasamy-rudram gravatar imageramasamy-rudram ( 2016-08-20 07:09:31 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-08-20 07:16:46 -0500

berak gravatar image

updated 2016-08-20 08:14:35 -0500

your cv::Mat image was never initialized, before you can draw something into it, you need to allocate memory for the pixels

imho, you need something like this:

//let's make an all black drawing image
cv::Mat image(480, 640, CV_8UC3, cv::Scalar::all(0)); // should be the size of the original image

cv::Vec3b color(140,160,160); // desired point color

for (p : points) {
      image.at<cv::Vec3b>(p) = color; // you can use Mat::at with a Point !      
}
edit flag offensive delete link more

Comments

This Mat is throwing intellisense error in visual studio. Which header should I include.

ramasamy-rudram gravatar imageramasamy-rudram ( 2016-08-20 07:45:40 -0500 )edit

use:

#include "opencv2/opencv.hpp"
using namespace cv; // <--  i guess, that's what you're missing !
berak gravatar imageberak ( 2016-08-20 07:50:35 -0500 )edit

The following isn't related to OpenCV though,

Now it's throwing while compiling

D:\Ram\Projects\DLib19\dlib-19.0\examples\face_landmark_detection_exram.cpp(109): error C2872: 'rectangle' : ambiguous symbol [D:\Ram\Projects\DLib19\dlib-19.0\examples\build\face_landmark_detection_exram.vcxproj] could be 'rectangle' or 'd:\ram\software\dlib\dlib-19.0\dlib\geometry/rectangle.h(20) : dlib::rectangle' D:\Ram\Projects\DLib19\dlib-19.0\examples\face_landmark_detection_exram.cpp(109): error C2923: 'std::vector' : 'cv::rec tangle' is not a valid template type argument for parameter '_Ty' [D:\Ram\Projects\DLib19\dlib-19.0\examples\build\face _landmark_detection_exram.vcxproj]

ramasamy-rudram gravatar imageramasamy-rudram ( 2016-08-20 08:01:56 -0500 )edit

ah, sorry. if you're using dlib there, don't try with using namespace cv. instead, specify cv::Mat , cv::Vec3b , cv::Scalar etc. with correct prefix

berak gravatar imageberak ( 2016-08-20 08:13:16 -0500 )edit

It throws the same.

ramasamy-rudram gravatar imageramasamy-rudram ( 2016-08-20 08:52:11 -0500 )edit

"D:\Ram\Projects\DLib19\dlib-19.0\examples\build\ALL_BUILD.vcxproj" (default target) (1) -> "D:\Ram\Projects\DLib19\dlib-19.0\examples\build\face_landmark_detection_exram.vcxproj" (default target) (5) -> (ClCompile target) -> D:\Ram\Projects\DLib19\dlib-19.0\examples\face_landmark_detection_exram.cpp(109): error C2872: 'rectangle' : ambiguou s symbol [D:\Ram\Projects\DLib19\dlib-19.0\examples\build\face_landmark_detection_exram.vcxproj] D:\Ram\Projects\DLib19\dlib-19.0\examples\face_landmark_detection_exram.cpp(109): error C2923: 'std::vector' : 'cv::r ectangle' is not a valid template type argument for parameter '_Ty' [D:\Ram\Projects\DLib19\dlib-19.0\examples\build\fa ce_landmark_detection_exram.vcxproj] D:\Ram\Projects\DLib19\dlib-19.0\examples\face_landmark_detection_exram.cpp(10

ramasamy-rudram gravatar imageramasamy-rudram ( 2016-08-20 08:53:13 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-08-20 04:29:08 -0500

Seen: 1,716 times

Last updated: Aug 20 '16