Reputation: 857
My project is already quite large as it is being used from another project, so I will not be able to add the entire code. I am working with Visual Studios 2015, OpenCV-3.1.0, and OpenNI2.
Through debugging I have been able to find the exact line which causes the error shown here:
This error occurs at the following line of code:
cvRectangle(&img_8bit, (pt1.x,pt1.y), (pt2.x,pt2.y), CV_RGB(255, 255, 255), -1);
The next image shows that there is data in each of these variable before the line is executed, it also shows the data types of each of the variables:
I've looked at few of the other posts that have appeared on this forum regarding a similar type of issue, but havent been able to find a solution that works in my case.
I have tried changing the way that the two points are entered by splitting it up into their x and y variables instead of just saying pt1 and pt2. I have also tried to change the way the image is entered, but with no success.
Can anyone tell if the issue is something related to the variables, or the rectangle function, or is it something else?
-----EDIT------------------ I have been able to recreate the error with a smaller amount of code so that everything can be shown. Note that if the cvRectangle line is commented out then it will display all the images perfectly from the stored location.
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <iostream>
#include <sstream>
#include <Windows.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
int nFrame = 0;//Current is the first few frames
cv::Mat depthMap;
char m_hitKey = 0;
char image_name[100];
CvPoint pt1, pt2;
pt1.x = 31;
pt1.y = 89;
pt2.x = 96;
pt2.y = 119;
for (int filenum = 0; filenum< 2276; filenum++)
{
++nFrame;//This is the first record at a few frames
std::sprintf(image_name, "%s%d%s", "C:\\Users\\James Mallett\\Dep\\dep-", filenum, ".png");
depthMap = cv::imread(image_name, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
if (m_hitKey = cv::waitKey(50))//Analyzing Key
{
if (m_hitKey == 27)
{
break;
}
}
cvRectangle(&depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
cv::imshow("RGB", depthMap);
}
cv::destroyAllWindows();
return 0;
}
Upvotes: 0
Views: 1269
Reputation: 16156
In your example:
cvRectangle(&depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
This looks very wrong, given that the signature I found online(yes, this is documentation of an earlier version, but this hasn't changed.) is ...
void cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8, int shift=0 )
... and depthMap
is of type cv:Mat
. Calling the C++ function with the matching signature named cv:rectangle
like this ...
cv:rectangle(depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
... would make more sense.
CvArr
is - according to the docs - a "meta type" (what a stupid choice of an API, IMO), thus it may point to any of plImage*
, CvMat*
or even CvSeq*
. Note that cv:Mat
is not in that list. I found a question on this site detailing how to convert between these types.
Upvotes: 1