コード例 #1
0
ファイル: gpu_perf.cpp プロジェクト: ankithasshastry/opencv
    void sortKeyPoints(std::vector<cv::KeyPoint>& keypoints, cv::InputOutputArray _descriptors)
    {
        std::vector<size_t> indexies(keypoints.size());
        for (size_t i = 0; i < indexies.size(); ++i)
            indexies[i] = i;

        std::sort(indexies.begin(), indexies.end(), KeypointIdxCompare(&keypoints));

        std::vector<cv::KeyPoint> new_keypoints;
        cv::Mat new_descriptors;

        new_keypoints.resize(keypoints.size());

        cv::Mat descriptors;
        if (_descriptors.needed())
        {
            descriptors = _descriptors.getMat();
            new_descriptors.create(descriptors.size(), descriptors.type());
        }

        for (size_t i = 0; i < indexies.size(); ++i)
        {
            size_t new_idx = indexies[i];
            new_keypoints[i] = keypoints[new_idx];
            if (!new_descriptors.empty())
                descriptors.row((int) new_idx).copyTo(new_descriptors.row((int) i));
        }

        keypoints.swap(new_keypoints);
        if (_descriptors.needed())
            new_descriptors.copyTo(_descriptors);
    }
コード例 #2
0
ファイル: flood_fill.cpp プロジェクト: AAAyag/FASText
int floodFill( std::vector<CvFFillSegment>& buffer, cv::InputOutputArray _imageId, cv::InputOutputArray _image, cv::Point seedPoint, int channel, double scaleFactor,
		int& compCounter, long threshold, int maxSize, int minCompSize, cv::Mat& segmImg, cv::Mat& segmMap, cv::Rect& rect, int& area, std::unordered_map<int, int>& keypointHash, std::vector<int>& keypointIds,  bool resegment,
		bool gradFill, int srcCols, cv::Scalar loDiff, cv::Scalar upDiff)
{
    CvConnectedComp ccomp;
    CvMat c_image = _image.getMat();
    CvMat c_imageId = _imageId.getMat();

    if(! resegment )
    {
    	int* checkRow = (int*) (c_imageId.data.ptr + seedPoint.y * c_imageId.step);
    	if(checkRow[seedPoint.x] > 0)
    		return checkRow[seedPoint.x];
    }

    compCounter++;

    floodFillC(buffer, &c_imageId, &c_image, seedPoint, channel, compCounter, loDiff, upDiff, &ccomp, threshold, maxSize, segmMap, gradFill);
    rect = ccomp.rect;

    if( ccomp.area == -1 )
    	return -2;

    if( ccomp.area < minCompSize )
    	return -1;

    segmImg = cv::Mat::zeros( ccomp.rect.height, ccomp.rect.width, CV_8UC1 );
    for (int y = 0; y < ccomp.rect.height; y++  )
    {
    	int* rowId  = (int*)(c_imageId.data.ptr + c_imageId.step * (y + ccomp.rect.y));
    	uchar* rowSegm = &segmImg.at<uchar>(y * segmImg.step);
    	int ybase = ((int) roundf(((y + ccomp.rect.y)))) * srcCols;
    	for(int x = 0; x <  ccomp.rect.width; x++)
    	{
    		if( rowId[x + ccomp.rect.x] == compCounter)
    		{
    			rowSegm[x] = 255;
    			int index = ( (ybase) + roundf((x + ccomp.rect.x)));
    			if( keypointHash.find( index ) != keypointHash.end()  )
    			{
    				keypointIds.push_back(keypointHash[index]);
    			}
#ifndef NDEBUG
    			segmMap.at<uchar>(y + ccomp.rect.y, x + ccomp.rect.x) = 255;
#endif
    		}
    	}
    }
    area = ccomp.area;
    return compCounter;
}
コード例 #3
0
ファイル: phasecorr.cpp プロジェクト: jakobwilm/slstudio
void fftShift(cv::InputOutputArray _out)
{
    cv::Mat out = _out.getMat();

    if(out.rows == 1 && out.cols == 1)
    {
        // trivially shifted.
        return;
    }

    std::vector<cv::Mat> planes;
    planes.push_back(out);

    int xMid = out.cols >> 1;
    int yMid = out.rows >> 1;

    bool is_1d = xMid == 0 || yMid == 0;

    if(is_1d)
    {
        xMid = xMid + yMid;

        for(size_t i = 0; i < planes.size(); i++)
        {
            Mat tmp;
            Mat half0(planes[i], Rect(0, 0, xMid, 1));
            Mat half1(planes[i], Rect(xMid, 0, xMid, 1));

            half0.copyTo(tmp);
            half1.copyTo(half0);
            tmp.copyTo(half1);
        }
    }
    else
    {
        for(size_t i = 0; i < planes.size(); i++)
        {
            // perform quadrant swaps...
            Mat tmp;
            Mat q0(planes[i], Rect(0,    0,    xMid, yMid));
            Mat q1(planes[i], Rect(xMid, 0,    xMid, yMid));
            Mat q2(planes[i], Rect(0,    yMid, xMid, yMid));
            Mat q3(planes[i], Rect(xMid, yMid, xMid, yMid));

            q0.copyTo(tmp);
            q3.copyTo(q0);
            tmp.copyTo(q3);

            q1.copyTo(tmp);
            q2.copyTo(q1);
            tmp.copyTo(q2);
        }
    }

    merge(planes, out);
}
コード例 #4
0
void expansionOfKnownRegions(cv::InputArray _img, cv::InputOutputArray _trimap, int niter)
{
    cv::Mat img = _img.getMat();
    cv::Mat &trimap = _trimap.getMatRef();

    if (img.empty())
        CV_Error(CV_StsBadArg, "image is empty");
    if (img.type() != CV_8UC3)
        CV_Error(CV_StsBadArg, "image mush have CV_8UC3 type");

    if (trimap.empty())
        CV_Error(CV_StsBadArg, "trimap is empty");
    if (trimap.type() != CV_8UC1)
        CV_Error(CV_StsBadArg, "trimap mush have CV_8UC1 type");

    if (img.size() != trimap.size())
        CV_Error(CV_StsBadArg, "image and trimap mush have same size");

    for (int i = 0; i < niter; ++i)
        expansionOfKnownRegionsHelper(img, trimap, i + 1, niter - i);
    erodeFB(trimap, 2);
}