Ask Your Question

# opencv-3.2.0(x64): drawContours does not work with Qt5

Hello,

I builded opencv 3.2.0 for x64 and try to use function drawContours in my Qt5 concole application, and it does not work. The code below.

 Mask = Mat(rows, cols, CV_8UC1, cv::Scalar(0));
const vector<Point> obj_corners = { Point(x_bgn, y_bgn), Point(x_end, y_bgn), Point(x_end, y_end), Point(x_bgn, y_end) };
const vector< vector<Point> >  co_ordinates = { obj_corners };
drawContours(Mask, co_ordinates, 0, Scalar(255), CV_FILLED);


The problem is that drawContours completes before it do something.

The source part of drawContours below.

void cv::drawContours( InputOutputArray _image, InputArrayOfArrays _contours,
int contourIdx, const Scalar& color, int thickness,
int lineType, InputArray _hierarchy,
int maxLevel, Point offset ){
CV_INSTRUMENT_REGION()

Mat image = _image.getMat(), hierarchy = _hierarchy.getMat();
CvMat _cimage = image;

size_t ncontours = _contours.total();
size_t i = 0, first = 0, last = ncontours;
std::vector<CvSeq> seq;
std::vector<CvSeqBlock> block;

if( !last )
return;


Variable last is false and drawContours complete. I found out that problem is method total() - it returns zero. The code below works exactly the same - ncount equal zero.

const vector<Point> obj_corners = { Point(x_bgn, y_bgn), Point(x_end, y_bgn), Point(x_end, y_end), Point(x_bgn, y_end) };
const vector< vector<Point> >  co_ordinates = { obj_corners };
InputArrayOfArrays con = co_ordinates;
size_t ncount = con.total();


In x86 verson of opencv all works fine. What I do wrong?

UPDATE: I am using Win7(x64) and VC14. I try to use standart build of opencv from archive opencv-3.2.0-vc14.exe and result the same. UPDATE2: Problem solved. In Debug configuration of my test project uses /MD key instead of /MDd(Project->Properties->C/C++->Code Generation->Runtime Library).

edit retag close merge delete

## Comments

1

I fixed copypaste error from my project to forum, but question is still actual.

if you want to see a result you cannot use Mat(rows, cols, CV_8UC1, cv::Scalar(255)); and filled contour with 255. Use Mat(rows, cols, CV_8UC1, cv::Scalar(0));

I fixed it. But drawContours still not work, because it complete before doing something with image.

## 2 answers

Sort by » oldest newest most voted

Problem solved. In Debug configuration of my test project uses /MD key instead of /MDd(Project->Properties->C/C++->Code Generation->Runtime Library).

more

With this code :

Mat Mask = Mat(100, 100, CV_8UC1, cv::Scalar(0));
const vector<Point> obj_corners = { Point(10, 20), Point(10, 40), Point(40, 40), Point(40, 10) };
const vector< vector<Point> >  co_ordinates = { obj_corners };
drawContours(Mask, co_ordinates, 0, Scalar(255), CV_FILLED);
imshow("rrrrr", Mask);
waitKey(); more

## Comments

It works only in x86 build. In x64 drawContours complete before the Mask changes.

No my version is opencv-3.2-dev is x64 with vs 2015. How do you manage x86 and x64 in your project?

I create standard Win32 console application instead Qt5 and it works!. But I use Qt 5.5.1, may be the problem in that. Will think. Thanks!

Save image (imwrite("m.png",Mask)) in your qt5 project and open it with paint may be image is good too

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2017-04-26 02:45:16 -0500

Seen: 344 times

Last updated: Apr 26 '17
{"ft_lang_label":"__label__en","ft_lang_prob":0.67412955,"math_prob":0.87376976,"size":2226,"snap":"2019-35-2019-39","text_gpt3_token_len":618,"char_repetition_ratio":0.11926193,"word_repetition_ratio":0.12179487,"special_character_ratio":0.27762803,"punctuation_ratio":0.23873875,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97327703,"pos_list":[0,1,2],"im_url_duplicate_count":[null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-22T11:05:30Z\",\"WARC-Record-ID\":\"<urn:uuid:369596fb-f87f-41d0-9d9c-4f5cf90f0e8f>\",\"Content-Length\":\"77902\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1a0a1930-07e2-479b-b1ab-4b4d7e118ad1>\",\"WARC-Concurrent-To\":\"<urn:uuid:4ef571d0-1701-42d7-a448-02d1560e5166>\",\"WARC-IP-Address\":\"5.9.49.245\",\"WARC-Target-URI\":\"https://answers.opencv.org/question/144024/opencv-320x64-drawcontours-does-not-work-with-qt5/?answer=144074\",\"WARC-Payload-Digest\":\"sha1:T3ZL3FKXB3XA2TIY4OI3OXBCSPSPPYXX\",\"WARC-Block-Digest\":\"sha1:5BE5EDPNQJH3ASR2TEZ2EEHGCBRSBNAQ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027317113.27_warc_CC-MAIN-20190822110215-20190822132215-00114.warc.gz\"}"}