Skip to content

Commit

Permalink
fixed crash on drawMarkers
Browse files Browse the repository at this point in the history
fixed wrong delete in destructor
  • Loading branch information
internaut committed Jun 23, 2014
1 parent b3aeb70 commit 23a7831
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions detect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ Detect::~Detect() {
// delete allocated memory

if (inFrameOrigGray) delete inFrameOrigGray;
if (inFrame) delete inFrame;
if (procFrame) delete procFrame;
if (outFrame) delete outFrame;
if (ident) delete ident;
Expand Down Expand Up @@ -205,7 +204,7 @@ void Detect::setFrameOutputLevel(FrameProcLevel level) {
printf("ocv_ar::Detect - set output frame level: %d (output frame size %dx%d)", level, outW, outH);
}

void Detect::setInputFrame(cv::Mat *frame) {
void Detect::setInputFrame(const cv::Mat *frame) {
assert(prepared && frame);

if (inputFrameCvtType >= 0) { // convert to grayscale
Expand Down Expand Up @@ -399,9 +398,20 @@ void Detect::identifyMarkers() {
if (outFrame && outFrameProcLvl == PROC_LEVEL_DETECTED_MARKERS) {
float r = it->getPerimeterRadius();
cv::Point o = it->getCentroid() - (0.5f * cv::Point2f(r, r));
// printf("ocv_ar::Detect - drawing marker with id %d at pos %d, %d\n", it->getId(), o.x, o.y);
cv::Rect roi(o, normMarkerImg.size());
cv::rectangle(*outFrame, roi, cv::Scalar(255,255,255,255));

if (roi.x + roi.width > outFrame->cols) {
roi.width = roi.x + roi.width - outFrame->cols;
}

if (roi.y + roi.height > outFrame->rows) {
roi.height = roi.y + roi.height - outFrame->rows;
}

// printf("ocv_ar::Detect - drawing marker with id %d at pos %d, %d with ROI at %d, %d (%d x %d)\n",
// it->getId(), o.x, o.y, roi.x, roi.y, roi.width, roi.height);

cv::Mat dstMat = (*outFrame)(roi);
normMarkerImg.copyTo(dstMat);

Expand Down
3 changes: 2 additions & 1 deletion detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ class Detect {

/**
* Set an input frame for processing.
* <frame> is a weak ref
* Note: You need to call <prepare()> before you can start processing frames!
*/
void setInputFrame(cv::Mat *frame);
void setInputFrame(const cv::Mat *frame);

/**
* Process the input frame to detect and identify markers.
Expand Down

0 comments on commit 23a7831

Please sign in to comment.