/** get the segmentation using active contour with initial mask. Note that the initalization has to be done before calling this function (for an unknown reason) * @param aSrc the source image * @param aInitMask the initial mask for the segementation * @param aMaxIts maximum number of iteration * @param aDisp if intermediate results is shown (1-0) */ cv::Mat GTVideo::segmentByActiveContour(const cv::Mat& aSrc, const cv::Mat& aInitMask, int aMaxIts, bool aDisp) { if (NULL == aSrc.data) { std::cerr << "Could not load the image." << std::endl; return cv::Mat(); } const int rows = aSrc.rows; const int cols = aSrc.cols; // set input parameters to the shared object libseg.so // source image (Note: matlab is column-major while C++ is row-major cv::Mat trImage; cv::transpose(aSrc, trImage); mwArray I(rows, cols, mxUINT8_CLASS); I.SetData(trImage.data, rows*cols); // maximum iteration number int maxits[1] = {aMaxIts}; mwArray max_its(1,1, mxINT32_CLASS);//mxUINT8_CLASS); max_its.SetData(maxits, 1); // initial mask of segmentation cv::Mat initmask = aInitMask.clone(); cv::transpose(initmask, initmask); mwArray init_mask(rows, cols, mxUINT8_CLASS); init_mask.SetData(initmask.data, rows*cols); // parameter alpha to the active contour method double alph[1] = {0.2}; mwArray alpha(1,1, mxDOUBLE_CLASS); alpha.SetData(alph, 1); // display intermediate results or not uchar disp[1] = {aDisp?1:0}; mwArray display(1,1, mxUINT8_CLASS); display.SetData(disp, 1); // return value container mwArray imOutput(rows, cols, mxUINT8_CLASS); region_seg(1, imOutput, I, init_mask, max_its, alpha, display); // retrieve result to cv::Mat format uchar result[rows*cols]; imOutput.GetData(result, rows*cols); cv::Mat retImage(rows, cols, CV_8UC1); for (int j=0; j<cols; j++) { for (int i=0; i<rows; i++) { retImage.at<uchar>(i,j) = result[j*rows+i]; } } return retImage; }
void ItemHttpMsg::onWebPageOver(bool bFinished) { QWebPage *page = _web->page(); if (page != nullptr) { QSize pageSize = page->mainFrame()->contentsSize(); QImage retImage(pageSize, QImage::Format_ARGB32_Premultiplied); QPainter p(&retImage); page->setViewportSize(pageSize); page->mainFrame()->render(&p); _image = retImage; update(); } }