Example #1
0
bool Utils::saveCvMat(const char* filename, const cv::Mat& image)
{
    if (!filename || strlen(filename) == 0)
        return false;

    FILE* file = NULL;

#ifdef _WIN32
    errno_t err = fopen_s(&file, filename, "wb");
    if(!file || err) {
        std::cerr << "could not create file: " << filename << std::endl;
        return false;
    }
#elif __APPLE__ & __MACH__
    file = fopen(filename, "wb");
    if(!file || ferror(file)) {
        cerr << "could not create file: " << filename << endl;
        return false;
    }
#endif

    // process roi information if available
    cv::Size origSize = cv::Size(0, 0);
    cv::Point startPoint = cv::Point(0, 0);

    image.locateROI(origSize, startPoint);
    int size = image.elemSize() * origSize.width * origSize.height;

    // header size
    const int headerSize = 3 * sizeof(char) +
        10 * sizeof(int);

    // write identification string
    fwrite("CVM", sizeof(char), 3, file);

    // write header
    fwrite(&headerSize, sizeof(int), 1, file);
    fwrite(&image.flags, sizeof(int), 1, file);
    fwrite(&image.cols, sizeof(int), 1, file);
    fwrite(&image.rows, sizeof(int), 1, file);
    fwrite(&image.dims, sizeof(int), 1, file);
    fwrite(&origSize.width, sizeof(int), 1, file);
    fwrite(&origSize.height, sizeof(int), 1, file);
    fwrite(&startPoint.x, sizeof(int), 1, file);
    fwrite(&startPoint.y, sizeof(int), 1, file);
    fwrite(&size, sizeof(int), 1, file);

    // write data
    fwrite(image.data, sizeof(uchar), size, file);

    fclose(file);

    return true;
}
Example #2
0
static inline void ippiGetImage(const cv::Mat &src, ::ipp::IwiImage &dst)
{
    ::ipp::IwiBorderSize inMemBorder;
    if(src.isSubmatrix()) // already have physical border
    {
        cv::Size  origSize;
        cv::Point offset;
        src.locateROI(origSize, offset);

        inMemBorder.left   = (IwSize)offset.x;
        inMemBorder.top    = (IwSize)offset.y;
        inMemBorder.right  = (IwSize)(origSize.width - src.cols - offset.x);
        inMemBorder.bottom = (IwSize)(origSize.height - src.rows - offset.y);
    }

    dst.Init(ippiSize(src.size()), ippiGetDataType(src.depth()), src.channels(), inMemBorder, (void*)src.ptr(), src.step);
}
unsigned long PeopleDetector::DetectColorFaces(cv::Mat& img, std::vector<cv::Rect>& faceCoordinates)
{
	IplImage imgPtr = (IplImage)img;
	CvSeq* faces = cvHaarDetectObjects(&imgPtr, m_face_cascade, m_storage, m_faces_increase_search_scale, m_faces_drop_groups, CV_HAAR_DO_CANNY_PRUNING,
			cvSize(m_faces_min_search_scale_x, m_faces_min_search_scale_y));

	cv::Size parentSize;
	cv::Point roiOffset;
	for (int i = 0; i < faces->total; i++)
	{
		cv::Rect* face = (cv::Rect*)cvGetSeqElem(faces, i);
		img.locateROI(parentSize, roiOffset);
		face->x += roiOffset.x; // todo: check what happens if the original matrix is used without roi
		face->y += roiOffset.y;
		faceCoordinates.push_back(*face);
	}

	return ipa_Utils::RET_OK;
}
Example #4
0
double BackgroundInitializationModule::sideMatch(cv::Mat ROI, cv::Mat block, bool isBlockImg)
{
	double SM_metric = 0.0;
	cv::Mat backup, vector;
	uchar *ptr_vector;
	cv::Size bgDimension;
	cv::Point ROIloc;
	bool growUp, growLeft, growRight, growBottom;

	if(isBlockImg)
	{
		ROI.copyTo(backup);
		block.copyTo(ROI);
	}

	ROI.locateROI(bgDimension, ROIloc);

	growUp = (ROIloc.y - 1 < 0)? false: true ;
	growLeft = (ROIloc.x - 1 < 0)? false: true ;
	growRight = (ROIloc.x + sizeBlock + 1 >= bgDimension.width)? false: true ;
	growBottom = (ROIloc.y + sizeBlock + 1  >= bgDimension.width)? false: true ;

	ROI.adjustROI(1,1,1,1); //grow 1 pixel in every direction
	if(growUp)
	{
		vector = block.row(0) - block.row(1);
		vector = vector.mul(vector);
		ptr_vector = vector.data;

		for(int i = 0; i < vector.rows*vector.cols; i++)
			SM_metric += ptr_vector[i];
	}
	if(growLeft)
	{
		vector = block.row(0) - block.row(1);
		vector = vector.mul(vector);
		ptr_vector = vector.data;

		for(int i = 0; i < vector.rows*vector.cols; i++)
			SM_metric += ptr_vector[i];
	}
	if(growRight)
	{
		vector = block.row(0) - block.row(1);
		vector = vector.mul(vector);
		ptr_vector = vector.data;

		for(int i = 0; i < vector.rows*vector.cols; i++)
			SM_metric += ptr_vector[i];
	}
	if(growBottom)
	{
		vector = block.row(0) - block.row(1);
		vector = vector.mul(vector);
		ptr_vector = vector.data;

		for(int i = 0; i < vector.rows*vector.cols; i++)
			SM_metric += ptr_vector[i];
	}


	if(isBlockImg)
		backup.copyTo(ROI);

	return SM_metric;
}