示例#1
0
文件: qr_impl.hpp 项目: cpplibivl/ivl
void qr<T>::output(array_2d<T>& x) const
{
	if(x.rows() != m || x.columns() != n)
		x.resize(idx(m, n));

	lapack_interface<T>::call_lapack_geqrf(x, a);
}
示例#2
0
文件: ivl_io.hpp 项目: iavr/drvq
void write_array_2d(const array_2d <T, K>& a, std::ostream& s)
{
	size_t arr = a.columns();  // number of arrays
	write_size(arr, s);

	size_t dim = a.rows();  // dimension of each array
	for (size_t n = 0, p = 0; n < arr; n++, p += dim) {
		write_size(dim, s);
		write(a[p], s, dim);
	}
}
示例#3
0
文件: qr_impl.hpp 项目: cpplibivl/ivl
void qr<T>::output(array_2d<T>& q, array_2d<T>& r) const
{
	array<T> tau(min_nm);

	if(r.rows() != m || r.columns() != n)
		r.resize(idx(m, n));

	lapack_interface<T>::call_lapack_geqrf(r, tau, a);

	//Now construct Q
	//Q should be a MxM matrix
	if(q.rows() != m || q.columns() != m)
		q.resize(idx(m, m));

	if(n <= m) {
		//Q can hold the MxN values of R needed by lapack's xORGQR routines
		for(size_t i = 0; i < m; i++)
			for(size_t j = 0; j < n; j++)
				q[m*j + i] = r(i,j);

		lapack_interface<T>::call_lapack_orgqr(q, tau);

	} else {
		//create a new array and do a copy since
		//Q cannot hold the MxN values of R as needed by lapack's xORGQR routines
		array_2d<T> temp_q(r(all(), size_range(0, m - 1)));

		lapack_interface<T>::call_lapack_orgqr(temp_q, tau);

		//copy the Q values from temp
		for(size_t i = 0; i < m; i++)
			for(size_t j = 0; j < m; j++)
				q[m*j + i] = temp_q[m*j + i];
	}

	// R is upper triangular
	for(size_t i = 0; i < m; i++)
		for(size_t j = 0; j < n; j++)
			if(i > j)
				r(i,j) = 0;
}
示例#4
0
typename image<T, D>::create_new get_quadrange_sub_pix(const image<T, D>& a,
		const array_2d<double>& map_matrix, const size_array& dst_size)
{
	IplImage* src = a.ipl();
	IplImage* dst;

	if(dst_size[0] == 0 && dst_size[1] == 0) {
		dst = cvCreateImage(cvGetSize(src),
		image_details::ipl_depth<T>(), int(a.channels()));
	} else {
		dst = cvCreateImage(cvSize(dst_size[1], dst_size[0]),
		image_details::ipl_depth<T>(), int(a.channels()));
	}

	CHECK(map_matrix.rows() == 2, eshape);
	CHECK(map_matrix.columns() == 2, eshape);

	CvMat* cvmap_matrix = cvCreateMat(2, 3, image_details::cv_type<double>());
	cvmSet(cvmap_matrix, 0, 0, map_matrix(0, 0));
	cvmSet(cvmap_matrix, 0, 1, map_matrix(0, 1));
	cvmSet(cvmap_matrix, 0, 2, map_matrix(0, 2));
	cvmSet(cvmap_matrix, 1, 0, map_matrix(1, 0));
	cvmSet(cvmap_matrix, 1, 1, map_matrix(1, 1));
	cvmSet(cvmap_matrix, 1, 2, map_matrix(1, 2));

	/*cvmap_matrix->data.db[0] = map_matrix(0, 0);
	cvmap_matrix->data.db[1] = map_matrix(0, 1);
	cvmap_matrix->data.db[2] = map_matrix(0, 2);
	cvmap_matrix->data.db[3] = map_matrix(1, 0);
	cvmap_matrix->data.db[4] = map_matrix(1, 1);
	cvmap_matrix->data.db[5] = map_matrix(1, 2);*/

	cvGetQuadrangleSubPix(src, dst, cvmap_matrix);

	typename image<T, D>::create_new r(dst);

	cvReleaseMat(&cvmap_matrix);
	cvReleaseImage(&src);
	cvReleaseImage(&dst);
	return r;
}