Пример #1
0
inline void bs::pattern::shiftPattern(cv::InputArray src, cv::OutputArray dst, const int direction, const int shift)
{
	cv::Mat d;
	cv::copyMakeBorder(src, d, shift, shift, shift, shift, cv::BORDER_WRAP);

	const auto direc = static_cast<Direction>(direction);

	switch (direc)
	{
	default:
		break;
	case Top:
		d = d(cv::Rect(cv::Point(shift, 2 * shift), src.size()));
		break;

	case Bottom:
		d = d(cv::Rect(cv::Point(shift, 0), src.size()));
		break;

	case Left:
		d = d(cv::Rect(cv::Point(2 * shift, shift), src.size()));
		break;

	case Right:
		d = d(cv::Rect(cv::Point(0, shift), src.size()));
		break;
	}
	d.copyTo(dst);
	return;
}
Пример #2
0
RadiometricResponse::RadiometricResponse(cv::InputArray _response, ChannelOrder order) : order_(order) {
  if (_response.size().width != 256 || _response.size().height != 1)
    BOOST_THROW_EXCEPTION(RadiometricResponseException("Radiometric response should have 1 x 256 size")
                          << RadiometricResponseException::Size(_response.size()));
  if (_response.type() != CV_32FC3)
    BOOST_THROW_EXCEPTION(RadiometricResponseException("Radiometric response values should be 3-channel float")
                          << RadiometricResponseException::Type(_response.type()));
  response_ = _response.getMat();
  cv::log(response_, log_response_);
  cv::split(response_, response_channels_);
}
Пример #3
0
void Picture::setAnimation(const AnimationEnum &animationEnum, 
	const cv::InputArray &startImg, const cv::InputArray &endImg)
{
	delete animation;

	Mat startImage = startImg.getMat();
	Mat endImage = endImg.getMat();
	if (!startImg.empty() && startImg.size() != this->size())
		cv::resize(startImg, startImage, this->size());
	if (!endImg.empty() && endImg.size() != this->size())
		cv::resize(endImg, endImage, this->size());
	
	animation = AnimationFactory::createAnimation(animationEnum, startImage, endImage);
}
Пример #4
0
void showWindow(const string &winName, cv::InputArray mat)
{
	Mat temp(mat.size(), mat.type());
	mat.getMat().copyTo(temp);
	namedWindow(winName, WINDOW_NORMAL); // Create a window for display.
	imshow(winName, temp); // Show our image inside it.
}
Пример #5
0
void warmify(cv::InputArray src, cv::OutputArray dst, uchar delta)
{
    CV_Assert(src.type() == CV_8UC3);
    Mat imgSrc = src.getMat();
    CV_Assert(imgSrc.data);
    dst.create(src.size(), CV_8UC3);
    Mat imgDst = dst.getMat();

    imgDst = imgSrc + Scalar(0, delta, delta);
}
    void findTemplateMatchCandidates(
        cv::InputArray image,
        cv::InputArray templ,
        cv::InputArray templMask,
        cv::OutputArray candidates,
        cv::Size partitionSize,
        int maxWeakErrors, 
        float maxMeanDifference)
    {
        TemplateMatchCandidates tmc;
        tmc.setSourceImage(image.getMat());
        tmc.setPartitionSize(partitionSize);
        tmc.setTemplateSize(templ.size());
        tmc.initialize();

        candidates.create(
            image.size().height - templ.size().height + 1, 
            image.size().width - templ.size().width + 1,            
            CV_8UC1);
        cv::Mat mat1 = templ.getMat(), mat2 = templMask.getMat(), mat3 = candidates.getMat();
        tmc.findCandidates(mat1, mat2, mat3, maxWeakErrors, maxMeanDifference);
    }
Пример #7
0
void RadiometricResponse::directMap(cv::InputArray _E, cv::OutputArray _I) const {
  if (_E.empty()) {
    _I.clear();
    return;
  }
  auto E = _E.getMat();
  _I.create(_E.size(), CV_8UC3);
  auto I = _I.getMat();
#if CV_MAJOR_VERSION > 2
  E.forEach<cv::Vec3f>(
      [&I, this](cv::Vec3f& v, const int* p) { I.at<cv::Vec3b>(p[0], p[1]) = inverseLUT(response_channels_, v); });
#else
  for (int i = 0; i < E.rows; i++)
    for (int j = 0; j < E.cols; j++) I.at<cv::Vec3b>(i, j) = inverseLUT(response_channels_, E.at<cv::Vec3f>(i, j));
#endif
}
Пример #8
0
void unprojectPointsFisheye( cv::InputArray distorted, cv::OutputArray undistorted, cv::InputArray K, cv::InputArray D, cv::InputArray R, cv::InputArray P)
{
    // will support only 2-channel data now for points
    CV_Assert(distorted.type() == CV_32FC2 || distorted.type() == CV_64FC2);
    undistorted.create(distorted.size(), CV_MAKETYPE(distorted.depth(), 3));

    CV_Assert(P.empty() || P.size() == cv::Size(3, 3) || P.size() == cv::Size(4, 3));
    CV_Assert(R.empty() || R.size() == cv::Size(3, 3) || R.total() * R.channels() == 3);
    CV_Assert(D.total() == 4 && K.size() == cv::Size(3, 3) && (K.depth() == CV_32F || K.depth() == CV_64F));

    cv::Vec2d f, c;
    if (K.depth() == CV_32F)
    {
        cv::Matx33f camMat = K.getMat();
        f = cv::Vec2f(camMat(0, 0), camMat(1, 1));
        c = cv::Vec2f(camMat(0, 2), camMat(1, 2));
    }
    else
    {
        cv::Matx33d camMat = K.getMat();
        f = cv::Vec2d(camMat(0, 0), camMat(1, 1));
        c = cv::Vec2d(camMat(0, 2), camMat(1, 2));
    }

    cv::Vec4d k = D.depth() == CV_32F ? (cv::Vec4d)*D.getMat().ptr<cv::Vec4f>(): *D.getMat().ptr<cv::Vec4d>();

    cv::Matx33d RR = cv::Matx33d::eye();
    if (!R.empty() && R.total() * R.channels() == 3)
    {
        cv::Vec3d rvec;
        R.getMat().convertTo(rvec, CV_64F);
        RR = cv::Affine3d(rvec).rotation();
    }
    else if (!R.empty() && R.size() == cv::Size(3, 3))
        R.getMat().convertTo(RR, CV_64F);

    if(!P.empty())
    {
        cv::Matx33d PP;
        P.getMat().colRange(0, 3).convertTo(PP, CV_64F);
        RR = PP * RR;
    }

    // start undistorting
    const cv::Vec2f* srcf = distorted.getMat().ptr<cv::Vec2f>();
    const cv::Vec2d* srcd = distorted.getMat().ptr<cv::Vec2d>();
    cv::Vec3f* dstf = undistorted.getMat().ptr<cv::Vec3f>();
    cv::Vec3d* dstd = undistorted.getMat().ptr<cv::Vec3d>();

    size_t n = distorted.total();
    int sdepth = distorted.depth();

    for(size_t i = 0; i < n; i++ )
    {
        cv::Vec2d pi = sdepth == CV_32F ? (cv::Vec2d)srcf[i] : srcd[i];  // image point
        cv::Vec2d pw((pi[0] - c[0])/f[0], (pi[1] - c[1])/f[1]);      // world point

        double theta_d = sqrt(pw[0]*pw[0] + pw[1]*pw[1]);
        double theta = theta_d;
        if (theta_d > 1e-8)
        {
            // compensate distortion iteratively
            for(int j = 0; j < 10; j++ )
            {
                double theta2 = theta*theta, theta4 = theta2*theta2, theta6 = theta4*theta2, theta8 = theta6*theta2;
                theta = theta_d / (1 + k[0] * theta2 + k[1] * theta4 + k[2] * theta6 + k[3] * theta8);
            }
        }
        double z = std::cos(theta);
        double r = std::sin(theta);

        cv::Vec3d pu = cv::Vec3d(r*pw[0], r*pw[1], z); //undistorted point

        // reproject
        cv::Vec3d pr = RR * pu; // rotated point optionally multiplied by new camera matrix
        cv::Vec3d fi;       // final
        normalize(pr, fi);

        if( sdepth == CV_32F )
            dstf[i] = fi;
        else
            dstd[i] = fi;
    }
}
Пример #9
0
bool VideoWriter_IntelMFX::write_one(cv::InputArray bgr)
{
    mfxStatus res;
    mfxFrameSurface1 *workSurface = 0;
    mfxSyncPoint sync;

    if (!bgr.empty() && (bgr.dims() != 2 || bgr.type() != CV_8UC3 || bgr.size() != frameSize))
    {
        MSG(cerr << "MFX: invalid frame passed to encoder: "
            << "dims/depth/cn=" << bgr.dims() << "/" << bgr.depth() << "/" << bgr.channels()
            << ", size=" << bgr.size() << endl);
        return false;

    }
    if (!bgr.empty())
    {
        workSurface = pool->getFreeSurface();
        if (!workSurface)
        {
            // not enough surfaces
            MSG(cerr << "MFX: Failed to get free surface" << endl);
            return false;
        }
        const int rows = workSurface->Info.Height;
        const int cols = workSurface->Info.Width;
        Mat Y(rows, cols, CV_8UC1, workSurface->Data.Y, workSurface->Data.Pitch);
        Mat UV(rows / 2, cols, CV_8UC1, workSurface->Data.UV, workSurface->Data.Pitch);
        to_nv12(bgr, Y, UV);
        CV_Assert(Y.ptr() == workSurface->Data.Y);
        CV_Assert(UV.ptr() == workSurface->Data.UV);
    }

    while (true)
    {
        outSurface = 0;
        DBG(cout << "Calling with surface: " << workSurface << endl);
        res = encoder->EncodeFrameAsync(NULL, workSurface, &bs->stream, &sync);
        if (res == MFX_ERR_NONE)
        {
            res = session->SyncOperation(sync, 1000); // 1 sec, TODO: provide interface to modify timeout
            if (res == MFX_ERR_NONE)
            {
                // ready to write
                if (!bs->write())
                {
                    MSG(cerr << "MFX: Failed to write bitstream" << endl);
                    return false;
                }
                else
                {
                    DBG(cout << "Write bitstream" << endl);
                    return true;
                }
            }
            else
            {
                MSG(cerr << "MFX: Sync error: " << res << endl);
                return false;
            }
        }
        else if (res == MFX_ERR_MORE_DATA)
        {
            DBG(cout << "ERR_MORE_DATA" << endl);
            return false;
        }
        else if (res == MFX_WRN_DEVICE_BUSY)
        {
            DBG(cout << "Waiting for device" << endl);
            sleep(1);
            continue;
        }
        else
        {
            MSG(cerr << "MFX: Bad status: " << res << endl);
            return false;
        }
    }
}
void savePointCloud(const std::string file, cv::InputArray point_cloud, const bool is_binary, cv::InputArray color_image, const bool remove_miss_point)
{
	const cv::Mat points = point_cloud.getMat();
	const bool color_cloud = (!color_image.empty() && (point_cloud.size() == color_image.size()));
	
	if (points.empty())
		return;

	if (points.type() != CV_32FC1)
		points.reshape(1, 3);

	if (color_cloud)
	{
		const cv::Mat im = color_image.getMat();
		pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);

		for (int row = 0; row < points.rows; ++row)
		{
			const auto ptr = points.ptr<cv::Vec3f>(row);
			const auto ptr_image = im.ptr<cv::Vec3b>(row);

			for (int col = 0; col < points.cols; ++col)
			{
				const auto val = ptr[col];
				const auto color = ptr_image[col];

				if (!remove_miss_point || (remove_miss_point && val[2] < 9999.9f))
				{
					pcl::PointXYZRGB p;
					p.x = val[0], p.y = val[1], p.z = val[2], p.r = color[0], p.g = color[1], p.b = color[2];
					cloud->push_back(p);
				}
			}
		}

		if (cloud->size() == 0)
			return;
		else if (is_binary)
			pcl::io::savePLYFileBinary(file, *cloud);
		else
			pcl::io::savePLYFileASCII(file, *cloud);
	}
	else
	{
		pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

		for (int row = 0; row < points.rows; ++row)
		{
			const auto ptr = points.ptr<cv::Vec3f>(row);

			for (int col = 0; col < points.cols; ++col)
			{
				const auto val = ptr[col];

				if (!remove_miss_point || (remove_miss_point && val[2] < 9999.9f))
					cloud->push_back(pcl::PointXYZ(val[0], val[1], val[2]));
			}
		}

		if (cloud->size() == 0)
			return;
		else if (is_binary)
			pcl::io::savePLYFileBinary(file, *cloud);
		else
			pcl::io::savePLYFileASCII(file, *cloud);
	}
	return;
}
Пример #11
0
void CvSVM_OCL::predict( cv::InputArray _samples, cv::OutputArray _results ) const
{
    _results.create(_samples.size().height, 1, CV_32F);
    CvMat samples = _samples.getMat(), results = _results.getMat();
    predict(&samples, &results);
}
	void disparityFitPlane(cv::InputArray disparity, cv::InputArray image, cv::OutputArray dest, int slicRegionSize, float slicRegularization, float slicMinRegionRatio, int slicMaxIteration, int ransacNumofSample, float ransacThreshold)
	{
		//disparityFitTest(ransacNumofSample, ransacThreshold);
		//cv::FileStorage pointxml("planePoint.xml", cv::FileStorage::WRITE); int err = 0;

		Mat segment;
		SLIC(image, segment, slicRegionSize, slicRegularization, slicMinRegionRatio, slicMaxIteration);
		
		vector<vector<Point3f>> points;
		SLICSegment2Vector3D_<float>(segment, disparity, 0, points);

		Mat disp32f = Mat::zeros(dest.size(), CV_32F);

		for (int i = 0; i < points.size(); ++i)
		{	
			if (points[i].size() < 3)
			{
				if (!points[i].empty())
				{
					for (int j = 0; j < points[i].size(); ++j)
					{
						points[i][j].z = 0.f;
					}
				}
			}
			else
			{
				Point3f abc;

				fitPlaneRANSAC(points[i], abc, ransacNumofSample, ransacThreshold, 1);

				//for refinement(if nessesary)
				int v = countArrowablePointDistanceZ(points[i], abc, ransacThreshold);
				/*double rate = (double)v / points[i].size() * 100;
				int itermax = 1;
				for (int n = 0; n < itermax;n++)
				{
					if (rate < 30)
					{
						//pointxml <<format("point%03d",err++)<< points[i];
						fitPlaneRANSAC(points[i], abc, ransacNumofSample, ransacThreshold, 1);
						v = countArrowablePointDistanceZ(points[i], abc, ransacThreshold);
						rate = (double)v / points[i].size() * 100;
					}
				}*/
	
				for (int j = 0; j < points[i].size(); ++j)
				{
					points[i][j].z = points[i][j].x*abc.x + points[i][j].y*abc.y + abc.z;
				}			
			}
		}

		SLICVector3D2Signal(points, image.size(), disp32f);
		if (disparity.depth() == CV_32F)
		{
			disp32f.copyTo(dest);
		}
		else if (disparity.depth() == CV_8U || disparity.depth() == CV_16U || disparity.depth() == CV_16S || disparity.depth() == CV_32S)
		{
			disp32f.convertTo(dest, disparity.type(), 1.0, 0.5);
		}
		else
		{
			disp32f.convertTo(dest, disparity.type());
		}
	}