one of arguments value out of range in cvPtr2D 40C

#include "highgui.h"

#include "cv.h"

#include "stdio.h"
///*#include "cxcore.h"
//#include "cvaux.h" /
#include

///
#include
//#include
//#include
//#include
//#include
//#include
//#include */
#include
using namespace std;
using namespace cv;

int main()
{
//multi原始图像
//himage 原始图像的hsv
//background 原始图像的17*17部分
//hbackground background的hsv

``````IplImage* multi = cvLoadImage("C:\\11.png");
IplImage* himage= cvCreateImage(cvGetSize(multi), IPL_DEPTH_8U, 3);
cvCvtColor(multi, himage, CV_BGR2HSV);
cvShowImage("himage", himage);
IplImage* background = multi;

cvSetImageROI(background, cvRect(300, 300, 17, 17));//设置源图像ROI
cvShowImage("background", background);

IplImage* hbackground = cvCreateImage(cvGetSize(background), IPL_DEPTH_8U, 3);
cvCvtColor(background, hbackground, CV_BGR2HSV);
cvShowImage("hbackground",hbackground);
CvScalar cs;
cs = cvAvg(hbackground);
int csmean = (cs.val + cs.val + cs.val) / 3;
cout << csmean << endl;
``````

double alpha = 0.7;
double beta = 2;
double th1 = 0.04;
double th2 = 0.2;
IplImage* shadow = cvCreateImage(cvGetSize(multi), IPL_DEPTH_8U, 1);
CvScalar white = 255;
CvScalar zero = 0;
int i = 20;
int j = 20;
double himageh, himages, himagev;
himageh = cvGet2D(himage, i, j).val;
himages = cvGet2D(himage, i, j).val;
himagev = cvGet2D(himage, i, j).val;
cout << himageh << endl;
cout << himages << endl;
cout << himagev << endl;
cout << cs.val << endl;

if ((himagev / (cs.val)) > alpha && (himagev / (cs.val)) < beta && himageh > th1 && himages > th2)
{
cout << 1 << endl;
}
else
{
cout << 0 << endl;
}
//for (int i = 0; i < multi->height; i++)
//{
// for (int j = 0; j < multi->width; j++)
// {
// if ((cvGet2D(himage, i, j).val) / (cs.val) > alpha && (cvGet2D(himage, i, j).val) / (cs.val) < beta && cvGet2D(himage, i, j).val > th1 && cvGet2D(himage, i, j).val > th2)
// {
// }
// else
// {
// }
// }
//}

cvWaitKey(0);
return 0;
}

1个回答

cvSetImageROI(background, cvRect(300, 300, 17, 17));//设置源图像ROI
cout << "cvGetSize(background): " << cvGetSize(background).width << " " << cvGetSize(background).height << endl;
//在设置了ROI过后，我获取了下宽高
//- 打印: cvGetSize(background): 17 17
{"ft_lang_label":"__label__zh","ft_lang_prob":0.6154221,"math_prob":0.9764248,"size":6708,"snap":"2020-45-2020-50","text_gpt3_token_len":3807,"char_repetition_ratio":0.12261336,"word_repetition_ratio":0.047477745,"special_character_ratio":0.31246272,"punctuation_ratio":0.17888562,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98659146,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-10-20T03:07:57Z\",\"WARC-Record-ID\":\"<urn:uuid:6ff87575-6bd5-4454-b471-986e622f5c27>\",\"Content-Length\":\"134694\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d1f208e6-b4ef-48c8-8fd6-a90f6d9b9b53>\",\"WARC-Concurrent-To\":\"<urn:uuid:5ee90401-848e-40cc-aa97-754941b41c04>\",\"WARC-IP-Address\":\"47.95.50.136\",\"WARC-Target-URI\":\"https://ask.csdn.net/questions/683105?sort=votes_count\",\"WARC-Payload-Digest\":\"sha1:NE3DNBNYFH6N7XJHHKLCPHSGGPKUTCAD\",\"WARC-Block-Digest\":\"sha1:PE5TPQDD4T7X5ZR3LX3TWU4AWWX3SECP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-45/CC-MAIN-2020-45_segments_1603107869785.9_warc_CC-MAIN-20201020021700-20201020051700-00161.warc.gz\"}"}