bool UKinect::pollInteraction()
{
	NUI_USER_INFO user;
	NUI_INTERACTION_FRAME Interaction_Frame;
	hr = interactionStream->GetNextFrame( 0, &Interaction_Frame );
	if (FAILED(hr))
	{
		cerr << hex << hr <<endl;
		cerr <<"[UKinect] WARNING: Interaction pool." << endl;
		return false;
	}

	for (int i = 0 ; i < NUI_SKELETON_COUNT; ++i)
	{
		user = Interaction_Frame.UserInfos[i];
		if (user.SkeletonTrackingId != 0) break;
	}

	NUI_HANDPOINTER_INFO handLeft = user.HandPointerInfos[0];
	NUI_HANDPOINTER_INFO handRight = user.HandPointerInfos[1];
	NUI_HANDPOINTER_STATE stateLeft  = (NUI_HANDPOINTER_STATE)handLeft.State;
	NUI_HANDPOINTER_STATE stateRight  = (NUI_HANDPOINTER_STATE)handRight.State;

	interID=user.SkeletonTrackingId;

	interLeftTracked= (bool)(stateLeft & NUI_HANDPOINTER_STATE_TRACKED);
	interLeftActive= (bool)(stateLeft & NUI_HANDPOINTER_STATE_PRESSED);
	interLeftInteractive= (bool)(stateLeft & NUI_HANDPOINTER_STATE_ACTIVE); 
	interLeftPressed= (bool)(stateLeft & NUI_HANDPOINTER_STATE_INTERACTIVE);

	interRightTracked=(bool)(stateRight & NUI_HANDPOINTER_STATE_TRACKED);
	interRightActive=(bool)(stateRight & NUI_HANDPOINTER_STATE_PRESSED);
	interRightInteractive=(bool)(stateRight & NUI_HANDPOINTER_STATE_ACTIVE);
	interRightPressed= (bool)(stateRight & NUI_HANDPOINTER_STATE_INTERACTIVE); 

	if (stateLeft!= NUI_HANDPOINTER_STATE_NOT_TRACKED)
	{
		interLeftX = handLeft.X;
		interLeftY = -handLeft.Y;
		interLeftRawX = handLeft.RawX;
		interLeftRawY = -handLeft.RawY;
		interLeftRawZ = handLeft.RawZ;
		interLeftPress = handLeft.PressExtent;
		if (handLeft.HandEventType>0) interLeftEvent = handLeft.HandEventType;
		//interLeftEvent = handLeft.HandEventType;
	}

	if (stateLeft!= NUI_HANDPOINTER_STATE_NOT_TRACKED)
	{
		interRightX = handRight.X;
		interRightY = -handRight.Y;
		interRightRawX = handRight.RawX;
		interRightRawY = -handRight.RawY;
		interRightRawZ = handRight.RawZ;
		interRightPress = handRight.PressExtent;
		if (handRight.HandEventType>0) interRightEvent = handRight.HandEventType;
		//interRightEvent = handRight.HandEventType;
	}

	if (interVisualization) {

		DWORD t_width, t_height;
		NuiImageResolutionToSize((NUI_IMAGE_RESOLUTION)colorResolution.as<int>(), t_width, t_height);

		if 
			((color)&&(interVisualizationOnColor.as<int>())) interCVMat=colorCVMat.clone(); // use color image as a background if color function enabled
		else
			interCVMat=Mat(Size(static_cast<int>(t_width), static_cast<int>(t_height)), CV_8UC3, CV_RGB( 0, 0, 0 ));

		if (stateLeft!= NUI_HANDPOINTER_STATE_NOT_TRACKED)
		{
			drawHand(user.SkeletonTrackingId,11,interRightEvent.as<int>(),interRightPressed.as<bool>(), interRightInteractive.as<bool>(), interRightPress.as<double>());
		}

		if (stateLeft!= NUI_HANDPOINTER_STATE_NOT_TRACKED)
		{
			drawHand(user.SkeletonTrackingId,7,interLeftEvent.as<int>(),interLeftPressed.as<bool>(),interLeftInteractive.as<bool>(),interLeftPress.as<double>());
		}

		interBin.image.width = interCVMat.cols;
		interBin.image.height = interCVMat.rows;
		interBin.image.size = interCVMat.cols * skeletonCVMat.rows * 3;
		interBin.image.data = interCVMat.data;
		interImage=interBin;

	}

	return true;
}
Пример #2
0
 boost::uint16_t BlockData::GetSubPieceNumber() const
 {
     return static_cast<boost::uint16_t>((Size() + SUB_PIECE_SIZE - 1) / SUB_PIECE_SIZE);
 }
Пример #3
0
void cv::cuda::graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& topLeft, GpuMat& topRight,
              GpuMat& bottom, GpuMat& bottomLeft, GpuMat& bottomRight, GpuMat& labels, GpuMat& buf, Stream& s)
{
#if (CUDA_VERSION < 5000)
    CV_Assert(terminals.type() == CV_32S);
#else
    CV_Assert(terminals.type() == CV_32S || terminals.type() == CV_32F);
#endif

    Size src_size = terminals.size();

    CV_Assert(leftTransp.size() == Size(src_size.height, src_size.width));
    CV_Assert(leftTransp.type() == terminals.type());

    CV_Assert(rightTransp.size() == Size(src_size.height, src_size.width));
    CV_Assert(rightTransp.type() == terminals.type());

    CV_Assert(top.size() == src_size);
    CV_Assert(top.type() == terminals.type());

    CV_Assert(topLeft.size() == src_size);
    CV_Assert(topLeft.type() == terminals.type());

    CV_Assert(topRight.size() == src_size);
    CV_Assert(topRight.type() == terminals.type());

    CV_Assert(bottom.size() == src_size);
    CV_Assert(bottom.type() == terminals.type());

    CV_Assert(bottomLeft.size() == src_size);
    CV_Assert(bottomLeft.type() == terminals.type());

    CV_Assert(bottomRight.size() == src_size);
    CV_Assert(bottomRight.type() == terminals.type());

    labels.create(src_size, CV_8U);

    NppiSize sznpp;
    sznpp.width = src_size.width;
    sznpp.height = src_size.height;

    int bufsz;
    nppSafeCall( nppiGraphcut8GetSize(sznpp, &bufsz) );

    ensureSizeIsEnough(1, bufsz, CV_8U, buf);

    cudaStream_t stream = StreamAccessor::getStream(s);

    NppStreamHandler h(stream);

    NppiGraphcutStateHandler state(sznpp, buf.ptr<Npp8u>(), nppiGraphcut8InitAlloc);

#if (CUDA_VERSION < 5000)
    nppSafeCall( nppiGraphcut8_32s8u(terminals.ptr<Npp32s>(), leftTransp.ptr<Npp32s>(), rightTransp.ptr<Npp32s>(),
        top.ptr<Npp32s>(), topLeft.ptr<Npp32s>(), topRight.ptr<Npp32s>(),
        bottom.ptr<Npp32s>(), bottomLeft.ptr<Npp32s>(), bottomRight.ptr<Npp32s>(),
        static_cast<int>(terminals.step), static_cast<int>(leftTransp.step), sznpp, labels.ptr<Npp8u>(), static_cast<int>(labels.step), state) );
#else
    if (terminals.type() == CV_32S)
    {
        nppSafeCall( nppiGraphcut8_32s8u(terminals.ptr<Npp32s>(), leftTransp.ptr<Npp32s>(), rightTransp.ptr<Npp32s>(),
            top.ptr<Npp32s>(), topLeft.ptr<Npp32s>(), topRight.ptr<Npp32s>(),
            bottom.ptr<Npp32s>(), bottomLeft.ptr<Npp32s>(), bottomRight.ptr<Npp32s>(),
            static_cast<int>(terminals.step), static_cast<int>(leftTransp.step), sznpp, labels.ptr<Npp8u>(), static_cast<int>(labels.step), state) );
    }
    else
    {
        nppSafeCall( nppiGraphcut8_32f8u(terminals.ptr<Npp32f>(), leftTransp.ptr<Npp32f>(), rightTransp.ptr<Npp32f>(),
            top.ptr<Npp32f>(), topLeft.ptr<Npp32f>(), topRight.ptr<Npp32f>(),
            bottom.ptr<Npp32f>(), bottomLeft.ptr<Npp32f>(), bottomRight.ptr<Npp32f>(),
            static_cast<int>(terminals.step), static_cast<int>(leftTransp.step), sznpp, labels.ptr<Npp8u>(), static_cast<int>(labels.step), state) );
    }
#endif

    if (stream == 0)
        cudaSafeCall( cudaDeviceSynchronize() );
}
Пример #4
0
 Size size()    const {
     return Size(2);
 }
Пример #5
0
Mat CharacterAnalysis::findOuterBoxMask()
{
    double min_parent_area = config->templateHeightPx * config->templateWidthPx * 0.10;	// Needs to be at least 10% of the plate area to be considered.

    int winningIndex = -1;
    int winningParentId = -1;
    int bestCharCount = 0;
    double lowestArea = 99999999999999;


    if (this->config->debugCharAnalysis)
        cout << "CharacterAnalysis::findOuterBoxMask" << endl;

    for (int imgIndex = 0; imgIndex < allContours.size(); imgIndex++)
    {
        //vector<bool> charContours = filter(thresholds[imgIndex], allContours[imgIndex], allHierarchy[imgIndex]);

        int charsRecognized = 0;
        int parentId = -1;
        bool hasParent = false;
        for (int i = 0; i < charSegments[imgIndex].size(); i++)
        {
            if (charSegments[imgIndex][i]) charsRecognized++;
            if (charSegments[imgIndex][i] && allHierarchy[imgIndex][i][3] != -1)
            {
                parentId = allHierarchy[imgIndex][i][3];
                hasParent = true;
            }
        }

        if (charsRecognized == 0)
            continue;

        if (hasParent)
        {
            double boxArea = contourArea(allContours[imgIndex][parentId]);
            if (boxArea < min_parent_area)
                continue;

            if ((charsRecognized > bestCharCount) ||
                    (charsRecognized == bestCharCount && boxArea < lowestArea))
                //(boxArea < lowestArea)
            {
                bestCharCount = charsRecognized;
                winningIndex = imgIndex;
                winningParentId = parentId;
                lowestArea = boxArea;
            }
        }


    }

    if (this->config->debugCharAnalysis)
        cout << "Winning image index is: " << winningIndex << endl;




    if (winningIndex != -1 && bestCharCount >= 3)
    {
        int longestChildIndex = -1;
        double longestChildLength = 0;
        // Find the child with the longest permiter/arc length ( just for kicks)
        for (int i = 0; i < allContours[winningIndex].size(); i++)
        {
            for (int j = 0; j < allContours[winningIndex].size(); j++)
            {
                if (allHierarchy[winningIndex][j][3] == winningParentId)
                {
                    double arclength = arcLength(allContours[winningIndex][j], false);
                    if (arclength > longestChildLength)
                    {
                        longestChildIndex = j;
                        longestChildLength = arclength;
                    }
                }
            }
        }





        Mat mask = Mat::zeros(thresholds[winningIndex].size(), CV_8U);

        // get rid of the outline by drawing a 1 pixel width black line
        drawContours(mask, allContours[winningIndex],
                     winningParentId, // draw this contour
                     cv::Scalar(255,255,255), // in
                     CV_FILLED,
                     8,
                     allHierarchy[winningIndex],
                     0
                    );


        // Morph Open the mask to get rid of any little connectors to non-plate portions
        int morph_elem  = 2;
        int morph_size = 3;
        Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );

        //morphologyEx( mask, mask, MORPH_CLOSE, element );
        morphologyEx( mask, mask, MORPH_OPEN, element );

        //morph_size = 1;
        //element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
        //dilate(mask, mask, element);


        // Drawing the edge black effectively erodes the image.  This may clip off some extra junk from the edges.
        // We'll want to do the contour again and find the larges one so that we remove the clipped portion.

        vector<vector<Point> > contoursSecondRound;

        findContours(mask, contoursSecondRound, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
        int biggestContourIndex = -1;
        double largestArea = 0;
        for (int c = 0; c < contoursSecondRound.size(); c++)
        {
            double area = contourArea(contoursSecondRound[c]);
            if (area > largestArea)
            {
                biggestContourIndex = c;
                largestArea = area;
            }
        }

        if (biggestContourIndex != -1)
        {
            mask = Mat::zeros(thresholds[winningIndex].size(), CV_8U);

            vector<Point> smoothedMaskPoints;
            approxPolyDP(contoursSecondRound[biggestContourIndex], smoothedMaskPoints, 2, true);

            vector<vector<Point> > tempvec;
            tempvec.push_back(smoothedMaskPoints);
            //fillPoly(mask, smoothedMaskPoints.data(), smoothedMaskPoints, Scalar(255,255,255));
            drawContours(mask, tempvec,
                         0, // draw this contour
                         cv::Scalar(255,255,255), // in
                         CV_FILLED,
                         8,
                         allHierarchy[winningIndex],
                         0
                        );



        }

        if (this->config->debugCharAnalysis)
        {
            vector<Mat> debugImgs;
            Mat debugImgMasked = Mat::zeros(thresholds[winningIndex].size(), CV_8U);

            thresholds[winningIndex].copyTo(debugImgMasked, mask);

            debugImgs.push_back(mask);
            debugImgs.push_back(thresholds[winningIndex]);
            debugImgs.push_back(debugImgMasked);

            Mat dashboard = drawImageDashboard(debugImgs, CV_8U, 1);
            displayImage(config, "Winning outer box", dashboard);
        }

        hasPlateMask = true;
        return mask;
    }

    hasPlateMask = false;
    Mat fullMask = Mat::zeros(thresholds[0].size(), CV_8U);
    bitwise_not(fullMask, fullMask);
    return fullMask;



}
Пример #6
0
void GrabCutMF::Demo(CStr &wkDir, float w1, float w2, float w3, float alpha, float beta, float gama, float mu)
{	
	CStr imgDir = wkDir + "Imgs/", salDir = wkDir + "Sal4N/", iluDir = wkDir + "Ilu4N/";
	vecS namesNE;
	int imgNum = CmFile::GetNamesNE(imgDir + "*.jpg", namesNE);
	CmFile::MkDir(salDir);
	CmFile::MkDir(iluDir);
	printf("w1 = %g, w2 = %g, w3 = %g, alpha = %g, beta = %g, gama = %g, mu = %g\n", w1, w2, w3, alpha, beta, gama, mu);

	// Number of labels
	//const int M = 2;
	CmTimer tm("Time"), tmIni("TimeIni"), tmRef("TimeRef");
	double maxWeight = 2; // 2: 0.958119, 1: 0.953818, 
	tm.Start();
#pragma omp parallel for
	for (int i = 0; i < imgNum; i++){
		printf("Processing %d/%d: %s%s.jpg%20s\r\n", i, imgNum, _S(imgDir), _S(namesNE[i]), "");
		CmFile::Copy(imgDir + namesNE[i] + ".jpg", salDir + namesNE[i] + ".jpg");
		//CmFile::Copy(imgDir + namesNE[i] + ".png", salDir + namesNE[i] + "_GT.png");
		Mat _imMat3u = imread(imgDir + namesNE[i] + ".jpg"), imMat3f, imMat3u, gt1u;
		Mat _gt1u = imread(imgDir + namesNE[i] + ".png", CV_LOAD_IMAGE_GRAYSCALE);
		if(_gt1u.rows == 0 && _gt1u.cols == 0) {
            cout<<"Error: unable to open "<<(imgDir + namesNE[i] + ".png")<<endl;
            continue;
		}
		blur(_gt1u, _gt1u, Size(3,3));
		Mat _res1u = Mat::zeros(_imMat3u.size(), CV_8U);
		Rect wkRect = CmCv::GetMaskRange(_gt1u, 30, 200);
		_imMat3u(wkRect).copyTo(imMat3u);
		_gt1u(wkRect).copyTo(gt1u);
		imMat3u.convertTo(imMat3f, CV_32FC3, 1/255.0);
		Rect rect = CmCv::GetMaskRange(gt1u, 5, 128);


		Mat edge1u; // Use an edge map to expand the background mask in flat (no edge) region
		CmCv::CannySimpleRGB(imMat3u, edge1u, 120, 1200, 5);
		dilate(edge1u, edge1u, Mat(), Point(-1, -1), 3);
		Mat borderMask1u(imMat3u.size(), CV_8U), tmpMask;
		memset(borderMask1u.data, 255, borderMask1u.step.p[0] * borderMask1u.rows);
		borderMask1u(rect) = Scalar(0);
		getGrabMask(edge1u, borderMask1u);


		//* The Mean field based GrabCut
		//tmIni.Start();
		GrabCutMF cutMF(imMat3f, imMat3u, salDir + namesNE[i], w1, w2, w3, alpha, beta, gama, mu);
		//Mat borderMask1u = CmCv::getGrabMask(imMat3u, rect), tmpMask;
		imwrite(salDir + namesNE[i] + "_BM.png", borderMask1u);
		imwrite(salDir + namesNE[i] + ".jpg", imMat3u);
		//imwrite(salDir + namesNE[i] + "_GT.png", gt1u);
		cutMF.initialize(rect, borderMask1u, (float)maxWeight, true);
		//cutMF.setGrabReg(rect, CmCv::getGrabMask(imMat3u, rect));
		//tmIni.Stop();
		//tmRef.Start();
		cutMF.refine();
		//tmRef.Stop();
		
		Mat res1u = cutMF.drawResult(), invRes1u;

		res1u.copyTo(_res1u(wkRect));
		imwrite(salDir + namesNE[i] + "_GCMF1.png", _res1u);

		//if (sum(res1u).val[0] < EPS){
		//	printf("%s.jpg don't contains a salient object\n", _S(namesNE[i]));
		//	continue;
		//}

		dilate(res1u(rect), tmpMask, Mat(), Point(-1, -1), 10);	
		bitwise_not(tmpMask, borderMask1u(rect));
		getGrabMask(edge1u, borderMask1u);

		//blur(res1u, invRes1u, Size(3, 3));
		//
		//PointSeti hullPnts;
		//convexHullOfMask(invRes1u, hullPnts);
		//fillConvexPoly(invRes1u, hullPnts, 255);
		//bitwise_not(invRes1u, invRes1u);
		//bitwise_or(invRes1u, borderMask1u, borderMask1u);
		imwrite(salDir + namesNE[i] + "_MB2.png", borderMask1u);

		
		//double w =  maxWeight - (maxWeight-1)*sum(res1u).val[0]/(borderMask1u.rows*borderMask1u.cols*255 - sum(borderMask1u).val[0]);
		cutMF.initialize(rect, borderMask1u, 2);
		cutMF.refine();

		//printf("weight = %g\n", w);
		//imshow("Result", res1u);
		//imshow("Possible", borderMask1u);
		//imshow("Image", imMat3f);
		//waitKey(0);

		res1u = cutMF.drawResult();

		Rect rectRes = CmCv::GetMaskRange(res1u, 5, 128);
		if (rectRes.width * 1.1 < rect.width || rectRes.height * 1.1 < rect.height){ // Too short result
			printf("%s.jpg contains a small object\n", _S(namesNE[i]));
			memset(borderMask1u.data, 255, borderMask1u.step.p[0] * borderMask1u.rows);
			borderMask1u(rect) = Scalar(0);
			cutMF.initialize(rect, borderMask1u, 2);
			cutMF.refine();
			res1u = cutMF.drawResult();
			imwrite(salDir + namesNE[i] + "_MB2.png", borderMask1u);
			CmFile::Copy2Dir(salDir + namesNE[i] + "*.*", iluDir);
			imwrite(iluDir + namesNE[i] + "_GCMF.png", _res1u);
		}

		res1u.copyTo(_res1u(wkRect));
		imwrite(salDir + namesNE[i] + "_GCMF.png", _res1u);
		
	}
	tm.Stop();
	double avgTime = tm.TimeInSeconds()/imgNum;
	printf("Speed: %gs, %gfps\t\t\n", avgTime, 1/avgTime);
	//tmIni.Report();
	//tmRef.Report();
	//CmEvaluation::EvalueMask(imgDir + "*.png", salDir, ".png", "_GC.png");

	
	char* pDes[] = { "GCMF1", "GCMF"}; //, "CudaG4", "Onecut", "GC", "CudaH", 
	vecS des  = charPointers2StrVec (pDes);
	CStr rootDir = CmFile::GetFatherFolder(wkDir), dbName = CmFile::GetNameNE(wkDir.substr(0, wkDir.size() - 1));
	CmEvaluation::EvalueMask(imgDir + "*.png", salDir, des, wkDir.substr(0, wkDir.size() - 1) + "Res.m", 0.3, false, "", dbName);
}
void FaceDetector::findFacesInImage(const Mat *img, vector<Rect> *res) {
	Mat tmp;
	// chuyển đổi hình ảnh sang màu xám và bình thường hóa biểu đồ:
	cvtColor(*img, tmp, CV_BGR2GRAY);

	//Cân bằng lại
	equalizeHist(tmp, tmp);

	// làm sạch vector
	res->clear();

	// phát hiện khuôn mặt:
	_cascade->detectMultiScale(tmp, *res, DET_SCALE_FACTOR, DET_MIN_NEIGHBORS, CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_SCALE_IMAGE, Size(30, 30));
}
bool FeatureHaar::eval(ImageRepresentation* image, Rect ROI, float* result) 
{
	*result = 0.0f;
	Point2D offset;
	offset = ROI;

	// define the minimum size
	Size minSize = Size(3,3);

	// printf("in eval %d = %d\n",curSize.width,ROI.width );

	if ( m_curSize.width != ROI.width || m_curSize.height != ROI.height )
	{
		m_curSize = ROI;
		if (!(m_initSize==m_curSize))
		{
			m_scaleFactorHeight = (float)m_curSize.height/m_initSize.height;
			m_scaleFactorWidth = (float)m_curSize.width/m_initSize.width;

			for (int curArea = 0; curArea < m_numAreas; curArea++)
			{
				m_scaleAreas[curArea].height = (int)floor((float)m_areas[curArea].height*m_scaleFactorHeight+0.5);
				m_scaleAreas[curArea].width = (int)floor((float)m_areas[curArea].width*m_scaleFactorWidth+0.5);

				if (m_scaleAreas[curArea].height < minSize.height || m_scaleAreas[curArea].width < minSize.width) {
					m_scaleFactorWidth = 0.0f;
					return false;
				}

				m_scaleAreas[curArea].left = (int)floor( (float)m_areas[curArea].left*m_scaleFactorWidth+0.5);
				m_scaleAreas[curArea].upper = (int)floor( (float)m_areas[curArea].upper*m_scaleFactorHeight+0.5);
				m_scaleWeights[curArea] = (float)m_weights[curArea] /
					(float)((m_scaleAreas[curArea].width)*(m_scaleAreas[curArea].height));  
			}
		}
		else
		{
			m_scaleFactorWidth = m_scaleFactorHeight = 1.0f;
			for (int curArea = 0; curArea<m_numAreas; curArea++) {
				m_scaleAreas[curArea] = m_areas[curArea];
				m_scaleWeights[curArea] = (float)m_weights[curArea] /
					(float)((m_areas[curArea].width)*(m_areas[curArea].height));
			}
		}
	}

	if ( m_scaleFactorWidth == 0.0f )
		return false;

	for (int curArea = 0; curArea < m_numAreas; curArea++)
	{
			*result += (float)image->getSum( m_scaleAreas[curArea]+offset )*
				m_scaleWeights[curArea];		

	}
	
	if (image->getUseVariance())
	{
		float variance = (float) image->getVariance(ROI);
		*result /=  variance;
	}

	m_response = *result;

	return true;
}
Пример #9
0
/*! \brief return current camera picture, as rgb or yuv picture, threadsave
 *
 * \param rgb if set to zero (default), yuv-Picture will return, <br>
 *            if set to other value, rgb-Picture will return
 * \param removeFrame if set to 1 (default) the next picture will be catch <br>
 *                    if set to zero, the last picture will be returned
 * \return SPicture pointer to lokal buffer, which didn't change until the next call from getPicture with
 *         the same rgb-parameter
 * \return NULL if any error occured
 */
SPicture* getPicture(int rgb/* = 0*/, int removeFrame/* = 1*/)
{
    if(mutex_lock(mutex))
        g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_lock</font>"));

    // if start wasn't called
    if(!g_run)
    {
        while(g_capture.isOpened())
            g_capture.release();
        printf("encoder.getPicture after call g_capture.release\n");
        g_Messages.push(string("getPicture</b> <font color='blue'>Kamera wurde geschlossen</font>"));
        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 1</font>"));
        return 0;
    }
    // try to open capture
    else if(!g_capture.isOpened())
    {
        g_Messages.push(string("getPicture</b> <font color='red'>keine Kamera geoeffnet!</font>"));
        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 2</font>"));
        return 0;
    }


    //get next or last picture
    Mat m, m2, m3;
    if(!removeFrame)
        g_capture.retrieve(m);
    else
        g_capture >> m; // get a new frame from camer

    if(!m.size().area())
    {
        g_Messages.push(string("getPicture</b> <font color='red'>picture from camera is empty</font>"));
        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 3</font>"));
        return 0;
    }

    //m = cvLoadImage("test.jpg");
    if(m.depth() != CV_8U)
    {
        g_Messages.push(string("getPicture</b> <font color='red'>depth != unsigned char</font>\n"));
        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 4</font>"));
        return 0;
    }
    //m.convertTo(m2, )
    //Scale Picture to choosen resolution (if camera didn't support it)
    Mat matrices[4];
    //IplImage src = m;
    //  IplImage* scaled = cvCreateImage(cvSize(g_cfg.width, g_cfg.height), IPL_DEPTH_8U, 3);

    //cvResize( &src, scaled, CV_INTER_LINEAR );
    m3.create(g_cfg.width, g_cfg.height, m.type());
    resize(m, m3, Size(g_cfg.width, g_cfg.height));

    char buffer[256];
    sprintf(buffer, "getPicture</b> <i>breite: %d, hoehe: %d, area: %d</i>", m.size().width, m.size().height, m.size().area());
    // g_Messages.push(string(buffer));

    //rgb-output
    if(rgb)
    {
        //imshow("LIVE", scaled);
        split(m3, matrices);
        matrices[3] = matrices[0].clone();
        matrices[3] = Scalar(255);
        merge(matrices, 4, m2);

        //get current buffer size and required buffer size
        int oldSize = picture_getSize(&g_rgbPicture);
        g_rgbPicture.width = m2.cols;
        g_rgbPicture.height = m2.rows;
        int newSize = picture_getSize(&g_rgbPicture);

        //compare buffer size and picture size, and make new buffer, if picture size differ
        if(oldSize != newSize)
        {
            picture_release(&g_rgbPicture);
            if(picture_create(&g_rgbPicture, m2.cols, m2.rows, 4))
            {
                g_Messages.push(string("getPicture</b> <font color='red'>Fehler beim speicher reservieren in getPicture rgb!</font>"));
                if(mutex_unlock(mutex))
                    g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 5</font>"));
                return NULL;
            }
        }

        //return 0;
        //copy picture to buffer
        size_t size = m2.cols*m2.rows*4;
        memcpy(g_rgbPicture.channel1, m2.data, size);

        //free scaled image
        //cvReleaseImage(&scaled);

        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 6</font>"));
        //return pointer to picture buffer
        return &g_rgbPicture;

    }
    // yuv-Output
    else
    {
        //convert and split picture
        cvtColor(m3, m2, CV_BGR2YCrCb);
        split(m2, matrices);

        IplImage* U = cvCreateImage(cvSize(m3.cols/2, m3.rows/2), IPL_DEPTH_8U, 1);
        IplImage* V = cvCreateImage(cvSize(m3.cols/2, m3.rows/2), IPL_DEPTH_8U, 1);
        IplImage uSrc = matrices[1];
        IplImage vSrc = matrices[2];
        //create resized u and v pictures (half-size)
        cvResize(&uSrc, U, CV_INTER_LINEAR);
        cvResize( &vSrc, V, CV_INTER_LINEAR );
        //  imshow("Y", matrices[0]);
        //imshow("U", U);
        //imshow("V", V);

        //get current buffer size and required buffer size
        int oldSize = picture_getSize(&g_yuvPicture);
        g_yuvPicture.width = m3.cols;
        g_yuvPicture.height = m3.rows;
        int newSize = picture_getSize(&g_yuvPicture);

        //compare buffer size and picture size, and make new buffer, if picture size differ
        if(oldSize != newSize)
        {
            picture_release(&g_yuvPicture);
            if(picture_create(&g_yuvPicture, m2.cols, m2.rows, 1))
            {
                g_Messages.push(string("getPicture</b> <font color='red'>Fehler beim speicher reservieren in getPicture yuv!</font>"));
                if(mutex_unlock(mutex))
                    g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 7</font>"));
                return 0;
            }
        }
        //return 0;
        //copy channels
        size_t size = m2.cols*m2.rows;
        memcpy(g_yuvPicture.channel1, matrices[0].data, size);
        memcpy(g_yuvPicture.channel2, V->imageData, size/4);
        memcpy(g_yuvPicture.channel3, U->imageData, size/4);

        //release u and v pictures
        cvReleaseImage(&U);
        cvReleaseImage(&V);
//       cvReleaseImage(&scaled);

        if(mutex_unlock(mutex))
            g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 8</font>"));
        //return pointer to picture buffer
        return &g_yuvPicture;
    }

    if(mutex_unlock(mutex))
        g_Messages.push(string("getPicture</b> <font color='red'>Fehler bei mutex_unlock 9</font>"));
    return NULL;
}
void FeatureHaar::generateRandomFeature(Size patchSize)
{	
	//maxcompute=-1000.0f;
	//mincompute=111110.0f;
	//maxcomputeresult=-1000000.0f;
	//mincomputeresult=111110.0f;
	//maxcomputegetsum=-1000000.0f;
	//mincomputegetsum=111110.0f;
	initflag=false;
	Point2D position;
	Size baseDim;
	Size sizeFactor;
	int area;

	Size minSize = Size(3,3);
	int minArea = 9;

	bool valid = false;
	while (!valid)
	{
		//chosse position and scale
		position.row = rand()%(patchSize.height);
		position.col = rand()%(patchSize.width);

		baseDim.width = (int) ((1-sqrt(1-(float)rand()/RAND_MAX))*patchSize.width);
		baseDim.height = (int) ((1-sqrt(1-(float)rand()/RAND_MAX))*patchSize.height);
		
		//select types
		//float probType[11] = {0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0909f, 0.0950f};
		float probType[11] = {0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
		float prob = (float)rand()/RAND_MAX;

		if (prob < probType[0]) 
		{
			//check if feature is valid
			sizeFactor.height = 2;
			sizeFactor.width = 1;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type1");
			m_numAreas = 2;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -1;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col;
			m_areas[1].upper = position.row+baseDim.height;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_initMean = 0;
			m_initSigma = INITSIGMA( m_numAreas ); 

			valid = true;

		}
		else if (prob < probType[0]+probType[1]) 
		{
			//check if feature is valid
			sizeFactor.height = 1;
			sizeFactor.width = 2;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type2");
			m_numAreas = 2;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -1;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col+baseDim.width;
			m_areas[1].upper = position.row;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_initMean = 0;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;

		}
		else if (prob < probType[0]+probType[1]+probType[2]) 
		{
			//check if feature is valid
			sizeFactor.height = 4;
			sizeFactor.width = 1;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type3");
			m_numAreas = 3;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -2;
			m_weights[2] = 1;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col;
			m_areas[1].upper = position.row+baseDim.height;
			m_areas[1].height = 2*baseDim.height;
			m_areas[1].width = baseDim.width;
			m_areas[2].upper = position.row+3*baseDim.height;
			m_areas[2].left = position.col;
			m_areas[2].height = baseDim.height;
			m_areas[2].width = baseDim.width;
			m_initMean = 0;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else if (prob < probType[0]+probType[1]+probType[2]+probType[3])
		{
		//check if feature is valid
			sizeFactor.height = 1;
			sizeFactor.width = 4;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type3");
			m_numAreas = 3;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -2;
			m_weights[2] = 1;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col+baseDim.width;
			m_areas[1].upper = position.row;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = 2*baseDim.width;
			m_areas[2].upper = position.row;
			m_areas[2].left = position.col+3*baseDim.width;
			m_areas[2].height = baseDim.height;
			m_areas[2].width = baseDim.width;
			m_initMean = 0;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4])
		{
		//check if feature is valid
			sizeFactor.height = 2;
			sizeFactor.width = 2;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type5");
			m_numAreas = 4;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -1;
			m_weights[2] = -1;
			m_weights[3] = 1;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col+baseDim.width;
			m_areas[1].upper = position.row;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_areas[2].upper = position.row+baseDim.height;
			m_areas[2].left = position.col;
			m_areas[2].height = baseDim.height;
			m_areas[2].width = baseDim.width;
			m_areas[3].upper = position.row+baseDim.height;
			m_areas[3].left = position.col+baseDim.width;
			m_areas[3].height = baseDim.height;
			m_areas[3].width = baseDim.width;
			m_initMean = 0;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5])
		{
			//check if feature is valid
			sizeFactor.height = 3;
			sizeFactor.width = 3;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type6");
			m_numAreas = 2;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -9;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = 3*baseDim.height;
			m_areas[0].width = 3*baseDim.width;
			m_areas[1].left = position.col+baseDim.width;
			m_areas[1].upper = position.row+baseDim.height;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_initMean = -8*128;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else if (prob< probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]) 
		{
			//check if feature is valid
			sizeFactor.height = 3;
			sizeFactor.width = 1;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type7");
			m_numAreas = 3;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -2;
			m_weights[2] = 1;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col;
			m_areas[1].upper = position.row+baseDim.height;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_areas[2].upper = position.row+baseDim.height*2;
			m_areas[2].left = position.col;
			m_areas[2].height = baseDim.height;
			m_areas[2].width = baseDim.width;
			m_initMean = 0;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]+probType[7])
		{
		//check if feature is valid
			sizeFactor.height = 1;
			sizeFactor.width = 3;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;

			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;

			if (area < minArea)
				continue;

			strcpy (m_type, "Type8");
			m_numAreas = 3;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -2;
			m_weights[2] = 1;
			m_areas= new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col+baseDim.width;
			m_areas[1].upper = position.row;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_areas[2].upper = position.row;
			m_areas[2].left = position.col+2*baseDim.width;
			m_areas[2].height = baseDim.height;
			m_areas[2].width = baseDim.width;
			m_initMean = 0;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]+probType[7]+probType[8])
		{
		//check if feature is valid
			sizeFactor.height = 3;
			sizeFactor.width = 3;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type9");
			m_numAreas = 2;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -2;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = 3*baseDim.height;
			m_areas[0].width = 3*baseDim.width;
			m_areas[1].left = position.col+baseDim.width;
			m_areas[1].upper = position.row+baseDim.height;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_initMean = 0;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else if (prob< probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]+probType[7]+probType[8]+probType[9]) 
		{
			//check if feature is valid
			sizeFactor.height = 3;
			sizeFactor.width = 1;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type10");
			m_numAreas = 3;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -1;
			m_weights[2] = 1;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col;
			m_areas[1].upper = position.row+baseDim.height;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_areas[2].upper = position.row+baseDim.height*2;
			m_areas[2].left = position.col;
			m_areas[2].height = baseDim.height;
			m_areas[2].width = baseDim.width;
			m_initMean = 128;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else if (prob < probType[0]+probType[1]+probType[2]+probType[3]+probType[4]+probType[5]+probType[6]+probType[7]+probType[8]+probType[9]+probType[10])
		{
		//check if feature is valid
			sizeFactor.height = 1;
			sizeFactor.width = 3;
			if (position.row + baseDim.height*sizeFactor.height >= patchSize.height ||
				position.col + baseDim.width*sizeFactor.width >= patchSize.width)
				continue;
			area = baseDim.height*sizeFactor.height*baseDim.width*sizeFactor.width;
			if (area < minArea)
				continue;

			strcpy (m_type, "Type11");
			m_numAreas = 3;
			m_weights = new int[m_numAreas];
			m_weights[0] = 1;
			m_weights[1] = -1;
			m_weights[2] = 1;
			m_areas = new Rect[m_numAreas];
			m_areas[0].left = position.col;
			m_areas[0].upper = position.row;
			m_areas[0].height = baseDim.height;
			m_areas[0].width = baseDim.width;
			m_areas[1].left = position.col+baseDim.width;
			m_areas[1].upper = position.row;
			m_areas[1].height = baseDim.height;
			m_areas[1].width = baseDim.width;
			m_areas[2].upper = position.row;
			m_areas[2].left = position.col+2*baseDim.width;
			m_areas[2].height = baseDim.height;
			m_areas[2].width = baseDim.width;
			m_initMean = 128;
			m_initSigma = INITSIGMA( m_numAreas ); 
			valid = true;
		}
		else
			assert (false);	
	}

	m_initSize = patchSize;
	m_curSize = m_initSize;
	m_scaleFactorWidth = m_scaleFactorHeight = 1.0f;
	m_scaleAreas = new Rect[m_numAreas];
	m_scaleWeights = new float[m_numAreas];
	for (int curArea = 0; curArea<m_numAreas; curArea++) {
		m_scaleAreas[curArea] = m_areas[curArea];
		m_scaleWeights[curArea] = (float)m_weights[curArea] /
			(float)(m_areas[curArea].width*m_areas[curArea].height);
	}
}
bool FeatureHaar::eval(CvHistogram*hist, ImageRepresentation* image, Rect ROI, float* result) 
{
	*result = 0.0f;
	Point2D offset;
	offset = ROI;

	// define the minimum size
	Size minSize = Size(3,3);

	// printf("in eval %d = %d\n",curSize.width,ROI.width );

	if ( m_curSize.width != ROI.width || m_curSize.height != ROI.height )
	{
		m_curSize = ROI;
		if (!(m_initSize==m_curSize))
		{
			m_scaleFactorHeight = (float)m_curSize.height/m_initSize.height;
			m_scaleFactorWidth = (float)m_curSize.width/m_initSize.width;

			for (int curArea = 0; curArea < m_numAreas; curArea++)
			{
				m_scaleAreas[curArea].height = (int)floor((float)m_areas[curArea].height*m_scaleFactorHeight+0.5);
				m_scaleAreas[curArea].width = (int)floor((float)m_areas[curArea].width*m_scaleFactorWidth+0.5);

				if (m_scaleAreas[curArea].height < minSize.height || m_scaleAreas[curArea].width < minSize.width) {
					m_scaleFactorWidth = 0.0f;
					return false;
				}

				m_scaleAreas[curArea].left = (int)floor( (float)m_areas[curArea].left*m_scaleFactorWidth+0.5);
				m_scaleAreas[curArea].upper = (int)floor( (float)m_areas[curArea].upper*m_scaleFactorHeight+0.5);
				m_scaleWeights[curArea] = (float)m_weights[curArea] /
					(float)((m_scaleAreas[curArea].width)*(m_scaleAreas[curArea].height));  
			}
		}
		else
		{
			m_scaleFactorWidth = m_scaleFactorHeight = 1.0f;
			for (int curArea = 0; curArea<m_numAreas; curArea++) {
				m_scaleAreas[curArea] = m_areas[curArea];
				m_scaleWeights[curArea] = (float)m_weights[curArea] /
					(float)((m_areas[curArea].width)*(m_areas[curArea].height));
			}
		}
	}

	if ( m_scaleFactorWidth == 0.0f )
		return false;

	for (int curArea = 0; curArea < m_numAreas; curArea++)
	{
			///////////////
			if(initflag)//cap nhat lan dau
			{		
				if(!image||!hist)
				{
					*result  += -1.0f;
					initflag=false;
					return false;
				}		
				float compute=(cvCompareHist(ref_histos,hist,CV_COMP_CORREL)-0.85)*255;		
				
				//if(compute>maxcompute)maxcompute=compute;
				//if(compute<mincompute)mincompute=compute;
				//printf("\nmax compute:%f,min compute:%f",maxcompute,mincompute);
				float k=(compute)*m_scaleWeights[curArea];
				*result +=k;
				//if(k>maxcomputeresult)maxcomputeresult=k;
				//if(k<mincomputeresult)mincomputeresult=k;					
				//printf("\nmax computerresult:%f,min computerresult:%f",maxcomputeresult,mincomputeresult);
			}
			else //lan dau la cap nhat hsv
			{
				if(!image||!hist)
				{
					*result  += -1.0f;
					return false;
				}
				initflag=true;
				//khoi tao lai
				//*result +=m_scaleWeights[curArea]; //ket qua cao nhat
				ref_histos=copyhistogram2(hist);
				float thresh=((rand() % 10000)*0.2f)/10000;	
				cvThreshHist(ref_histos,thresh);
				float compute=(cvCompareHist(ref_histos,hist,CV_COMP_CORREL)-0.85)*255;
				float k=(compute)*m_scaleWeights[curArea];
				*result +=k;
			}
			//////////////			
			float k=(float)image->getSum( m_scaleAreas[curArea]+offset )*
			m_scaleWeights[curArea];
			*result += k;
			//if(k>maxcomputegetsum)maxcomputegetsum=k;
			//if(k<mincomputegetsum)mincomputegetsum=k;
			//printf("\nmax computerget sum:%f,min computeget sum:%f",maxcomputegetsum,mincomputegetsum);
	}
	
	if (image->getUseVariance())
	{
		float variance = (float) image->getVariance(ROI);
		*result /=  variance;
	}

	m_response = *result;

	return true;
}
Пример #12
0
WebSocketTest::WebSocketTest()
: _wsiSendText(nullptr)
, _wsiSendBinary(nullptr)
, _wsiError(nullptr)
, _sendTextStatus(nullptr)
, _sendBinaryStatus(nullptr)
, _errorStatus(nullptr)
, _sendTextTimes(0)
, _sendBinaryTimes(0)
{
    auto winSize = Director::getInstance()->getWinSize();
    
    const int MARGIN = 40;
    const int SPACE = 35;
    
    auto menuRequest = Menu::create();
    menuRequest->setPosition(Vec2::ZERO);
    addChild(menuRequest);
    
    // Send Text
    auto labelSendText = Label::createWithTTF("Send Text", "fonts/arial.ttf", 20);
    auto itemSendText = MenuItemLabel::create(labelSendText, CC_CALLBACK_1(WebSocketTest::onMenuSendTextClicked, this));
    itemSendText->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN - SPACE));
    menuRequest->addChild(itemSendText);
    
    labelSendText = Label::createWithTTF("Send Multiple Text", "fonts/arial.ttf", 20);
    itemSendText = MenuItemLabel::create(labelSendText, CC_CALLBACK_1(WebSocketTest::onMenuSendMultipleTextClicked, this));
    itemSendText->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN - 2 * SPACE));
    menuRequest->addChild(itemSendText);
    
    // Send Binary
    auto labelSendBinary = Label::createWithTTF("Send Binary", "fonts/arial.ttf", 20);
    auto itemSendBinary = MenuItemLabel::create(labelSendBinary, CC_CALLBACK_1(WebSocketTest::onMenuSendBinaryClicked, this));
    itemSendBinary->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN - 3 * SPACE));
    menuRequest->addChild(itemSendBinary);
    

    // Send Text Status Label
    _sendTextStatus = Label::createWithTTF("Send Text WS is waiting...", "fonts/arial.ttf", 16, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP);
    _sendTextStatus->setAnchorPoint(Vec2(0, 0));
    _sendTextStatus->setPosition(Vec2(VisibleRect::left().x, VisibleRect::rightBottom().y + 25));
    this->addChild(_sendTextStatus);
    
    // Send Binary Status Label
    _sendBinaryStatus = Label::createWithTTF("Send Binary WS is waiting...", "fonts/arial.ttf", 16, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP);
    _sendBinaryStatus->setAnchorPoint(Vec2(0, 0));
    _sendBinaryStatus->setPosition(Vec2(VisibleRect::left().x + 160, VisibleRect::rightBottom().y + 25));
    this->addChild(_sendBinaryStatus);
    
    // Error Label
    _errorStatus = Label::createWithTTF("Error WS is waiting...", "fonts/arial.ttf", 16, Size(160, 100), TextHAlignment::CENTER, TextVAlignment::TOP);
    _errorStatus->setAnchorPoint(Vec2(0, 0));
    _errorStatus->setPosition(Vec2(VisibleRect::left().x + 320, VisibleRect::rightBottom().y + 25));
    this->addChild(_errorStatus);
    
    auto startTestLabel = Label::createWithTTF("Start Test WebSocket", "fonts/arial.ttf", 16);
    auto startTestItem = MenuItemLabel::create(startTestLabel, CC_CALLBACK_1(WebSocketTest::startTestCallback, this));
    startTestItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + 150));
    _startTestMenu = Menu::create(startTestItem, nullptr);
    _startTestMenu->setPosition(Vec2::ZERO);
    this->addChild(_startTestMenu, 1);
}
shared_ptr<Patch> AggregatedFeaturesExtractor::extract(int centerX, int centerY, int width, int height) const {
	Rect boundsInImagePixels = Patch::computeBounds(Point(centerX, centerY), Size(width, height));
	return extract(boundsInImagePixels);
}
Пример #14
0
Size LineEdit::GetFontSize() const {
	FontInfo fi = font.Info();
	return Size(max(fi['M'], fi['W']), fi.GetHeight());
}
Пример #15
0
///////////////////////////////////////////////////////
// Panel::CalibrateCamera() Description
///////////////////////////////////////////////////////
void Panel::CalibrateCamera(string sFilePath)
{
	help();

	//! [file_read]
	Settings s;
	const string inputSettingsFile = sFilePath;
	FileStorage fs(inputSettingsFile, FileStorage::READ); // Read the settings
	if (!fs.isOpened())
	{
		cout << "Could not open the configuration file: \"" << inputSettingsFile << "\"" << endl;
//		return -1;
	}
	fs["Settings"] >> s;
	fs.release();                                         // close Settings file
	//! [file_read]

	//FileStorage fout("settings.yml", FileStorage::WRITE); // write config as YAML
	//fout << "Settings" << s;

	if (!s.goodInput)
	{
		cout << "Invalid input detected. Application stopping. " << endl;
//		return -1;
	}

	vector<vector<Point2f> > imagePoints;
	Mat cameraMatrix, distCoeffs;
	Size imageSize;
	int mode = s.inputType == Settings::IMAGE_LIST ? CAPTURING : DETECTION;
	clock_t prevTimestamp = 0;
	const Scalar RED(0, 0, 255), GREEN(0, 255, 0);
	const char ESC_KEY = 27;
	int counter = 1;

	//! [get_input]
	for (;;)
	{
		Mat view;
		bool blinkOutput = false;

		view = s.nextImage();

		//-----  If no more image, or got enough, then stop calibration and show result -------------
		if (mode == CAPTURING && imagePoints.size() >= (size_t)s.nrFrames)
		{
			if (runCalibrationAndSave(s, imageSize, cameraMatrix, distCoeffs, imagePoints))
				mode = CALIBRATED;
			else
				mode = DETECTION;
		}
		if (view.empty())          // If there are no more images stop the loop
		{
			// if calibration threshold was not reached yet, calibrate now
			if (mode != CALIBRATED && !imagePoints.empty())
				runCalibrationAndSave(s, imageSize, cameraMatrix, distCoeffs, imagePoints);
			break;
		}
		//! [get_input]

		imageSize = view.size();  // Format input image.
		if (s.flipVertical)    flip(view, view, 0);

		//! [find_pattern]
		vector<Point2f> pointBuf;

		bool found;
		switch (s.calibrationPattern) // Find feature points on the input format
		{
		case Settings::CHESSBOARD:
			found = findChessboardCorners(view, s.boardSize, pointBuf,
				CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK | CALIB_CB_NORMALIZE_IMAGE);
			break;
		case Settings::CIRCLES_GRID:
			found = findCirclesGrid(view, s.boardSize, pointBuf);
			break;
		case Settings::ASYMMETRIC_CIRCLES_GRID:
			found = findCirclesGrid(view, s.boardSize, pointBuf, CALIB_CB_ASYMMETRIC_GRID);
			break;
		default:
			found = false;
			break;
		}
		//! [find_pattern]
		//! [pattern_found]
		if (found)                // If done with success,
		{
			// improve the found corners' coordinate accuracy for chessboard
			if (s.calibrationPattern == Settings::CHESSBOARD)
			{
				Mat viewGray;
				cvtColor(view, viewGray, COLOR_BGR2GRAY);
				cornerSubPix(viewGray, pointBuf, Size(11, 11),
					Size(-1, -1), TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 30, 0.1));
			}

			if (mode == CAPTURING &&  // For camera only take new samples after delay time
				(!s.inputCapture.isOpened() || clock() - prevTimestamp > s.delay*1e-3*CLOCKS_PER_SEC))
			{
				imagePoints.push_back(pointBuf);
				prevTimestamp = clock();
				blinkOutput = s.inputCapture.isOpened();
			}

			// Draw the corners.
			drawChessboardCorners(view, s.boardSize, Mat(pointBuf), found);
		}
		//! [pattern_found]
		//----------------------------- Output Text ------------------------------------------------
		//! [output_text]
		string msg = (mode == CAPTURING) ? "100/100" :
			mode == CALIBRATED ? "Calibrated" : "Press 'g' to start";
		int baseLine = 0;
		Size textSize = getTextSize(msg, 1, 1, 1, &baseLine);
		Point textOrigin(view.cols - 2 * textSize.width - 10, view.rows - 2 * baseLine - 10);

		if (mode == CAPTURING)
		{
			if (s.showUndistorsed)
				msg = format("%d/%d Undist", (int)imagePoints.size(), s.nrFrames);
			else
				msg = format("%d/%d", (int)imagePoints.size(), s.nrFrames);
		}

		putText(view, msg, textOrigin, 1, 1, mode == CALIBRATED ? GREEN : RED);

		if (blinkOutput)
			bitwise_not(view, view);
		//! [output_text]
		//------------------------- Video capture  output  undistorted ------------------------------
		//! [output_undistorted]
		if (mode == CALIBRATED && s.showUndistorsed)
		{
			Mat temp = view.clone();
			undistort(temp, view, cameraMatrix, distCoeffs);
		}
		//! [output_undistorted]
		//------------------------------ Show image and check for input commands -------------------
		//! [await_input]
		
		namedWindow("Image View" + to_string(counter), WINDOW_NORMAL);
		resizeWindow("Image View" + to_string(counter), 640, 480);
		imshow("Image View" + to_string(counter), view);
		char key = (char)waitKey(s.inputCapture.isOpened() ? 50 : s.delay);

		cout << "Image " << to_string(counter) << " Completed" << endl;
		counter++;

		if (key == ESC_KEY)
			break;

		if (key == 'u' && mode == CALIBRATED)
			s.showUndistorsed = !s.showUndistorsed;

		if (s.inputCapture.isOpened() && key == 'g')
		{
			mode = CAPTURING;
			imagePoints.clear();
		}
		//! [await_input]
	}

	// -----------------------Show the undistorted image for the image list ------------------------
	//! [show_results]
	if (s.inputType == Settings::IMAGE_LIST && s.showUndistorsed)
	{
		Mat view, rview, map1, map2;
		initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(),
			getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize, 0),
			imageSize, CV_16SC2, map1, map2);

		m_mainMap1 = map1;
		m_mainMap2 = map2;

		for (size_t i = 0; i < s.imageList.size(); i++)
		{
			view = imread(s.imageList[i], 1);
			if (view.empty())
				continue;
			remap(view, rview, map1, map2, INTER_LINEAR);
			imshow("Image View", rview);
			char c = (char)waitKey();
			if (c == ESC_KEY || c == 'q' || c == 'Q')
				break;
		}
	}
	//! [show_results]

//	return 0;

}
Пример #16
0
GameParameterForLevels::GameParameterForLevels(int _levelNum, Size _mapSize, ArcherParameter* _archerParameter, std::vector<EnemyParameter*> _enemyParameter, std::vector<EdgeParameter*> _edgeParameter) {
    levelNum = _levelNum;
    archerParameter = _archerParameter;
    enemyParameter = _enemyParameter;
    edgeParameter = _edgeParameter;
    mapSize = _mapSize;
}

//全局参数

Vec2 ParameterManager::gravity = Vec2(0, -200);
Vec2 ParameterManager::getGravity() {
    return gravity;
}

Size ParameterManager::visibleSize = Size(1024,640);
Size ParameterManager::getVisibleSize() {
    return visibleSize;
}

GameParameterForLevels* ParameterManager::level1GameParameter = NULL;
GameParameterForLevels* ParameterManager::level2GameParameter = NULL;
GameParameterForLevels* ParameterManager::level3GameParameter = NULL;
GameParameterForLevels* ParameterManager::level4GameParameter = NULL;
GameParameterForLevels* ParameterManager::level5GameParameter = NULL;

GameParameterForLevels* ParameterManager::getGameParameterInstance(int _levelNum) {
    switch (_levelNum) {
    case 1:
        //第一关
        if (level1GameParameter == NULL) {
Пример #17
0
void GLView::setFrameSize(float width, float height)
{
    _screenSize = Size(width, height);
}
Пример #18
0
GameParameterForLevels* ParameterManager::getGameParameterInstance(int _levelNum) {
    switch (_levelNum) {
    case 1:
        //第一关
        if (level1GameParameter == NULL) {
            auto archer = new ArcherParameter(Vec2(80, 120));

            std::vector<EnemyParameter*>enemyParameterVector;
            enemyParameterVector.push_back(new EnemyParameter(Vec2(500, 100), 5, 1));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(600, 100), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1800, 100), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1700, 100), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(900, 130), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1100, 130), 15, 3));

            std::vector<EdgeParameter*>groundParameterVector;  //最后的参数,1是地板,用来站的,2是墙壁
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 0), Vec2(0, 640), 2));//左墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(2048, 0), Vec2(2048, 640), 2));//右墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 60), Vec2(713, 60), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(803, 93), Vec2(1280, 93), 1));//其他地板2
            groundParameterVector.push_back(new EdgeParameter(Vec2(1407, 63), Vec2(2046, 63), 1));//其他地板3
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 0), Vec2(2046, 0), 1));//其他地板3

            level1GameParameter = new GameParameterForLevels(1, Size(2048, 640), archer, enemyParameterVector, groundParameterVector);
        }
        return level1GameParameter;

    case 2:
        //第二关
        if (level2GameParameter == NULL) {
            auto archer = new ArcherParameter(Vec2(100, 520));

            std::vector<EnemyParameter*>enemyParameterVector;
            enemyParameterVector.push_back(new EnemyParameter(Vec2(350, 420), 10, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(500, 300), 10, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(680, 450), 10, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(900, 500), 10, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1080, 400), 10, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1200, 470), 10, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1430, 470), 10, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1600, 370), 10, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1800, 450), 10, 3));

            std::vector<EdgeParameter*>groundParameterVector;  //最后的参数,1是地板,用来站的,2是墙壁
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 0), Vec2(0, 640), 2));//左墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(2048, 0), Vec2(2048, 640), 2));//右墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(70, 456), Vec2(244, 456), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(310, 356), Vec2(402, 356), 1));//其他地板2
            groundParameterVector.push_back(new EdgeParameter(Vec2(465, 232), Vec2(573, 232), 1));//其他地板3
            groundParameterVector.push_back(new EdgeParameter(Vec2(625, 370), Vec2(718, 370), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(830, 437), Vec2(923, 437), 1));//其他地板2
            groundParameterVector.push_back(new EdgeParameter(Vec2(1031, 341), Vec2(1123, 341), 1));//其他地板3
            groundParameterVector.push_back(new EdgeParameter(Vec2(1194, 402), Vec2(1321, 402), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(1397, 400), Vec2(1489, 400), 1));//其他地板2
            groundParameterVector.push_back(new EdgeParameter(Vec2(1530, 297), Vec2(1678, 297), 1));//其他地板3
            groundParameterVector.push_back(new EdgeParameter(Vec2(1733, 385), Vec2(1962, 385), 1));//其他地板1

            level2GameParameter = new GameParameterForLevels(2, Size(2048, 640), archer, enemyParameterVector, groundParameterVector);
        }
        return level2GameParameter;

    case 3:
        //第三关
        if (level3GameParameter == NULL) {
            auto archer = new ArcherParameter(Vec2(80, 120));

            std::vector<EnemyParameter*>enemyParameterVector;
            enemyParameterVector.push_back(new EnemyParameter(Vec2(400, 120), 5, 1));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(450, 170), 5, 1));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(700, 170), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(800, 170), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(900, 170), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(300, 400), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(500, 400), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(800, 640), 15, 3));
            //enemyParameterVector.push_back(new EnemyParameter(Vec2(700, 170), 100, 5));

            std::vector<EdgeParameter*>groundParameterVector;  //最后的参数,1是地板,用来站的,2是墙壁
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 90), Vec2(1280, 90), 1));//地板
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 95), Vec2(0, 928), 2));//左墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(1280, 95), Vec2(1280, 928), 2));//右墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(600, 148), Vec2(1160, 148), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(260, 378), Vec2(830, 378), 1));//其他地板2
            groundParameterVector.push_back(new EdgeParameter(Vec2(600, 618), Vec2(1180, 618), 1));//其他地板3
            groundParameterVector.push_back(new EdgeParameter(Vec2(935, 300), Vec2(935, 619), 3));//绳子1

            level3GameParameter = new GameParameterForLevels(3, Size(1280, 928), archer, enemyParameterVector, groundParameterVector);
        }
        return level3GameParameter;

    case 4:
        //第四关
        if (level4GameParameter == NULL) {
            auto archer = new ArcherParameter(Vec2(80, 130));

            std::vector<EnemyParameter*>enemyParameterVector;
            enemyParameterVector.push_back(new EnemyParameter(Vec2(400, 430), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(500, 430), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(500, 890), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(600, 890), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(950, 180), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1050, 180), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1300, 270), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1400, 270), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1300, 770), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1400, 770), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(1600, 950), 15, 3));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 300), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 400), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 500), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 600), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 700), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 800), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 900), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 1000), 20, 4));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(80, 1100), 20, 4));

            std::vector<EdgeParameter*>groundParameterVector;  //最后的参数,1是地板,用来站的,2是墙壁
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 43), Vec2(2046, 43), 1));//地板
            groundParameterVector.push_back(new EdgeParameter(Vec2(347, 180), Vec2(347, 391), 3));//绳子1
            groundParameterVector.push_back(new EdgeParameter(Vec2(59, 390), Vec2(663, 390), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(609, 540), Vec2(609, 869), 3));//绳子1
            groundParameterVector.push_back(new EdgeParameter(Vec2(95, 868), Vec2(700, 868), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(800, 153), Vec2(1213, 153), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(1620, 180), Vec2(1620, 248), 3));//绳子1
            groundParameterVector.push_back(new EdgeParameter(Vec2(1285, 247), Vec2(1892, 247), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(1343, 400), Vec2(1343, 741), 3));//绳子1
            groundParameterVector.push_back(new EdgeParameter(Vec2(1212, 740), Vec2(1868, 740), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(1562, 914), Vec2(1739, 914), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 0), Vec2(0, 640), 2));//左墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(2048, 0), Vec2(2048, 1280), 2));//右墙

            level4GameParameter = new GameParameterForLevels(4, Size(2048, 1280), archer, enemyParameterVector, groundParameterVector);
        }
        return level4GameParameter;

    case 5:
        //第五关
        if (level5GameParameter == NULL) {
            auto archer = new ArcherParameter(Vec2(80, 130));

            std::vector<EnemyParameter*>enemyParameterVector;
            enemyParameterVector.push_back(new EnemyParameter(Vec2(700, 120), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(800, 120), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(300, 120), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(400, 120), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(700, 180), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(800, 180), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(300, 180), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(400, 180), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(700, 250), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(800, 250), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(300, 250), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(400, 250), 10, 2));
            enemyParameterVector.push_back(new EnemyParameter(Vec2(500, 500), 1000, 5));

            std::vector<EdgeParameter*>groundParameterVector;  //最后的参数,1是地板,用来站的,2是墙壁
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 0), Vec2(0, 640), 2));//左墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(1024, 0), Vec2(1024, 640), 2));//右墙
            groundParameterVector.push_back(new EdgeParameter(Vec2(0, 94), Vec2(1022, 94), 1));//其他地板1
            groundParameterVector.push_back(new EdgeParameter(Vec2(276, 216), Vec2(770, 216), 1));//其他地板2
            groundParameterVector.push_back(new EdgeParameter(Vec2(352, 350), Vec2(700, 350), 1));//其他地板3

            level5GameParameter = new GameParameterForLevels(5, Size(1024, 640), archer, enemyParameterVector, groundParameterVector);
        }
        return level5GameParameter;
    default:
        return NULL;
    }
}
Пример #19
0
bool ReceivedBundleElement::IsBundle() const
{
    return (Size() > 0 && Contents()[0] == '#');
}
Пример #20
0
void
LayerManagerComposite::PopGroupForLayerEffects(RefPtr<CompositingRenderTarget> aPreviousTarget,
                                               IntRect aClipRect,
                                               bool aGrayscaleEffect,
                                               bool aInvertEffect,
                                               float aContrastEffect)
{
  MOZ_ASSERT(mTwoPassTmpTarget);

  // This is currently true, so just making sure that any new use of this
  // method is flagged for investigation
  MOZ_ASSERT(aInvertEffect || aGrayscaleEffect || aContrastEffect != 0.0);

  mCompositor->SetRenderTarget(aPreviousTarget);

  EffectChain effectChain(RootLayer());
  Matrix5x4 effectMatrix;
  if (aGrayscaleEffect) {
    // R' = G' = B' = luminance
    // R' = 0.2126*R + 0.7152*G + 0.0722*B
    // G' = 0.2126*R + 0.7152*G + 0.0722*B
    // B' = 0.2126*R + 0.7152*G + 0.0722*B
    Matrix5x4 grayscaleMatrix(0.2126f, 0.2126f, 0.2126f, 0,
                              0.7152f, 0.7152f, 0.7152f, 0,
                              0.0722f, 0.0722f, 0.0722f, 0,
                              0,       0,       0,       1,
                              0,       0,       0,       0);
    effectMatrix = grayscaleMatrix;
  }

  if (aInvertEffect) {
    // R' = 1 - R
    // G' = 1 - G
    // B' = 1 - B
    Matrix5x4 colorInvertMatrix(-1,  0,  0, 0,
                                 0, -1,  0, 0,
                                 0,  0, -1, 0,
                                 0,  0,  0, 1,
                                 1,  1,  1, 0);
    effectMatrix = effectMatrix * colorInvertMatrix;
  }

  if (aContrastEffect != 0.0) {
    // Multiplying with:
    // R' = (1 + c) * (R - 0.5) + 0.5
    // G' = (1 + c) * (G - 0.5) + 0.5
    // B' = (1 + c) * (B - 0.5) + 0.5
    float cP1 = aContrastEffect + 1;
    float hc = 0.5*aContrastEffect;
    Matrix5x4 contrastMatrix( cP1,   0,   0, 0,
                                0, cP1,   0, 0,
                                0,   0, cP1, 0,
                                0,   0,   0, 1,
                              -hc, -hc, -hc, 0);
    effectMatrix = effectMatrix * contrastMatrix;
  }

  effectChain.mPrimaryEffect = new EffectRenderTarget(mTwoPassTmpTarget);
  effectChain.mSecondaryEffects[EffectTypes::COLOR_MATRIX] = new EffectColorMatrix(effectMatrix);

  gfx::Rect clipRectF(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
  mCompositor->DrawQuad(Rect(Point(0, 0), Size(mTwoPassTmpTarget->GetSize())), clipRectF, effectChain, 1.,
                        Matrix4x4());
}
Пример #21
0
void
CommandLineArguments::parse_args(int argc, char** argv)
{
  for(int i = 1; i < argc; ++i)
  {
    std::string arg = argv[i];

    if (arg == "--version" || arg == "-v")
    {
      m_action = PRINT_VERSION;

    }
    else if (arg == "--help" || arg == "-h")
    {
      m_action = PRINT_HELP;
    }
    else if (arg == "--print-datadir")
    {
      m_action = PRINT_DATADIR;
    }
    else if (arg == "--debug")
    {
      m_log_level = LOG_DEBUG;
    }
    else if (arg == "--verbose")
    {
      if (m_log_level < LOG_INFO)
      {
        m_log_level = LOG_INFO;
      }
    }
    else if (arg == "--datadir")
    {
      if (i+1 >= argc)
      {
        throw std::runtime_error("Need to specify a directory for --datadir");
      }
      else
      {
        datadir = argv[++i];
      }
    }
    else if (arg == "--userdir")
    {
      if (i+1 >= argc)
      {
        throw std::runtime_error("Need to specify a directory for --userdir");
      }
      else
      {
        userdir = argv[++i];
      }
    }
    else if (arg == "--fullscreen" || arg == "-f")
    {
      use_fullscreen = true;
    }
    else if (arg == "--default" || arg == "-d")
    {
      use_fullscreen = false;

      window_size = Size(1280, 800);
      fullscreen_size = Size(1280, 800);
      fullscreen_refresh_rate = 0;
      aspect_size = Size(0, 0);  // auto detect
    }
    else if (arg == "--window" || arg == "-w")
    {
      use_fullscreen = false;
    }
    else if (arg == "--geometry" || arg == "-g")
    {
      i += 1;
      if (i >= argc)
      {
        throw std::runtime_error("Need to specify a size (WIDTHxHEIGHT) for geometry argument");
      }
      else
      {
        int width, height;
        if (sscanf(argv[i], "%9dx%9d", &width, &height) != 2)
        {
          throw std::runtime_error("Invalid geometry spec, should be WIDTHxHEIGHT");
        }
        else
        {
          window_size     = Size(width, height);
          fullscreen_size = Size(width, height);
          fullscreen_refresh_rate = 0;
        }
      }
    }
    else if (arg == "--aspect" || arg == "-a")
    {
      i += 1;
      if (i >= argc)
      {
        throw std::runtime_error("Need to specify a ratio (WIDTH:HEIGHT) for aspect ratio");
      }
      else
      {
        int aspect_width  = 0;
        int aspect_height = 0;
        if (strcmp(argv[i], "auto") == 0)
        {
          aspect_width  = 0;
          aspect_height = 0;
        }
        else if (sscanf(argv[i], "%9d:%9d", &aspect_width, &aspect_height) != 2)
        {
          throw std::runtime_error("Invalid aspect spec, should be WIDTH:HEIGHT or auto");
        }
        else
        {
          float aspect_ratio = static_cast<float>(aspect_width) / static_cast<float>(aspect_height);

          // use aspect ratio to calculate logical resolution
          if (aspect_ratio > 1) {
            aspect_size = Size(static_cast<int>(600 * aspect_ratio + 0.5),
                                         600);
          } else {
            aspect_size = Size(600,
                                         static_cast<int>(600 * 1/aspect_ratio + 0.5));
          }
        }
      }
    }
    else if (arg == "--renderer")
    {
      i += 1;
      if (i >= argc)
      {
        throw std::runtime_error("Need to specify a renderer for renderer argument");
      }
      else
      {
        video = VideoSystem::get_video_system(argv[i]);
      }
    }
    else if (arg == "--show-fps")
    {
      show_fps = true;
    }
    else if (arg == "--no-show-fps")
    {
      show_fps = false;
    }
    else if (arg == "--developer")
    {
      developer_mode = true;
    }
    else if (arg == "--christmas")
    {
      christmas_mode = true;
    }
    else if (arg == "--no-christmas")
    {
      christmas_mode = false;
    }
    else if (arg == "--disable-sound" || arg == "--disable-sfx")
    {
      sound_enabled = false;
    }
    else if (arg == "--disable-music")
    {
      music_enabled = false;
    }
    else if (arg == "--play-demo")
    {
      if (i+1 >= argc)
      {
        throw std::runtime_error("Need to specify a demo filename");
      }
      else
      {
        start_demo = argv[++i];
      }
    }
    else if (arg == "--record-demo")
    {
      if (i+1 >= argc)
      {
        throw std::runtime_error("Need to specify a demo filename");
      }
      else
      {
        record_demo = argv[++i];
      }
    }
    else if (arg == "--spawn-pos") 
    {
      Vector spawn_pos;
      
      if (!start_level)
        throw std::runtime_error("--spawn-pos can only be used when a levelfile is specified.");
      
      if (++i >= argc)
        throw std::runtime_error("Need to specify a spawn-pos X,Y");
      else
      {
        int x, y;
        if (sscanf(argv[i], "%9d,%9d", &x, &y) != 2)
          throw std::runtime_error("Invalid spawn-pos, should be X,Y");
        spawn_pos.x = x;
        spawn_pos.y = y;
      }
      
      tux_spawn_pos = spawn_pos;
    }
    else if (arg == "--debug-scripts" || arg == "-s")
    {
      enable_script_debugger = true;
    }
    else if (arg[0] != '-')
    {
      start_level = arg;
    }
    else
    {
      throw std::runtime_error((boost::format("Unknown option '%1%''. Use --help to see a list of options") % arg).str());
    }
  }
}
Пример #22
0
Size TextField::getTouchSize()
{
    return Size(_touchWidth, _touchHeight);
}
Пример #23
0
 Size factors() const {
     return Size(2);
 }
Пример #24
0
////////////////////////////////////////////////////////////
// Helper Function for Cascade Classifier	
//  Note: Cascade classifier is not currently used 
//  by this application. We left the functions associated
//  with this method for future reference. 
////////////////////////////////////////////////////////////
void detectAndDisplay(Mat image, string panel_cascade_name)
{
	CascadeClassifier panel_cascade;
	if (!panel_cascade.load(panel_cascade_name)){ printf("--(!)Error loading\n"); return; };

	std::vector<Rect> detectedPanels;
	Mat frame_gray;

	cvtColor(image, frame_gray, CV_BGR2GRAY);
	equalizeHist(frame_gray, frame_gray);

	//-- Detect faces
	panel_cascade.detectMultiScale(frame_gray, detectedPanels, 1.1, 20, 0 | CV_HAAR_SCALE_IMAGE, Size(200, 200));

	for (size_t i = 0; i < detectedPanels.size(); i++)
	{
		Point topLeft(detectedPanels[i].x, detectedPanels[i].y);
		Point botRight(detectedPanels[i].x + detectedPanels[i].width, detectedPanels[i].y + detectedPanels[i].height);
		rectangle(image, topLeft, botRight, Scalar(0, 0, 255), 4);
}
	//-- Show what you got
	imshow("Classifier Result", image);
}
 PyrLkOptFlowEstimatorBase() { setWinSize(Size(21, 21)); setMaxLevel(3); }
Пример #26
0
///////////////////////////////////////////////////////////////////
// Panel::CannyDetection() 
// Description: This function is called by DetectEdges() and it
//  is the Canny edge detection function which does not contain
//  debugging statements. We run the image through several different 
//  image processing functions to prepare the image before edge
//  detection. After detection the edges we run Hough lines which 
//  approximates lines of minimum length as specified in 
//  Settings.xml. We find all intersections of the Hough lines 
//  then make a minimum area rectangle around the intersections to 
//  approximate the edges of the panel which we are trying to
//  measure. From there we use the unit conversion calculated 
//  in DetectFeatures() to find a length and width of the current
//  panel. We report the length and width with a message box. 
///////////////////////////////////////////////////////////////////
Mat Panel::CannyDetection(Mat image, bool showImg)
{
	Mat greyImage;
	cvtColor(image, greyImage, CV_BGR2GRAY);

	Mat eroded, dilated, thresh, blurredThresh, edges, edgesGray;
	vector<Vec2f> lines;

		threshold(greyImage, thresh, m_lowCannyThreshold, 255, THRESH_BINARY);
		erode(thresh, eroded, Mat());
		dilate(eroded, dilated, Mat());
		GaussianBlur(thresh, blurredThresh, Size(7, 7), m_sigmaX, m_sigmaY);
		Canny(blurredThresh, edges, m_cannyLow, m_cannyLow*m_ratio, 3);
		HoughLines(edges, lines, 1, CV_PI / 180, m_houghLength, 0, 0);

		cvtColor(edges, edgesGray, CV_GRAY2BGR);
		for (size_t i = 0; i < lines.size(); i++)
		{
			float rho = lines[i][0], theta = lines[i][1];
			Point pt1, pt2;
			double a = cos(theta), b = sin(theta);
			double x0 = a*rho, y0 = b*rho;
			pt1.x = cvRound(x0 + 1000 * (-b));
			pt1.y = cvRound(y0 + 1000 * (a));
			pt2.x = cvRound(x0 - 1000 * (-b));
			pt2.y = cvRound(y0 - 1000 * (a));
			line(edgesGray, pt1, pt2, Scalar(0, 0, 255), 3, CV_AA);
		}

		////////////////////////////////////////////////////////
		// Compute the intersection from the lines detected
		////////////////////////////////////////////////////////
		vector<Point2f> intersections;
		for (size_t i = 0; i < lines.size(); i++)
		{
			for (size_t j = 0; j < lines.size(); j++)
			{
				Vec2f line1 = lines[i];
				Vec2f line2 = lines[j];
				if (acceptLinePair(line1, line2, (float)CV_PI / 32))
				{
					Point2f intersection = computeIntersect(line1, line2);
					if (intersection.x >= 0 && intersection.y >= 0)
						intersections.push_back(intersection);
				}
			}
		}

		if (intersections.size() > 0)
		{
			vector<Point2f>::iterator i;
			for (i = intersections.begin(); i != intersections.end(); ++i)
			{
				cout << "Intersection is " << i->x << ", " << i->y << endl;
				circle(image, *i, 2, Scalar(0, 255, 0), 3);
			}
			// Find the minimum bounding rectangle
			RotatedRect rect;
			Point2f rectPoints[4];
			Scalar color = Scalar(255, 0, 0);
			if (intersections.size() == 4)
			{
				// TODO
			}
			rect = minAreaRect(intersections);
			rect.points(rectPoints);
			int j = 0;
			for (j; j < 4; j++)
				line(image, rectPoints[j], rectPoints[(j + 1) % 4], color, 5, 8);

			float topLength = (float)norm(rectPoints[1] - rectPoints[0]);
			float botLength = (float)norm(rectPoints[3] - rectPoints[2]);
			float panelWidthPixels = topLength < botLength ? topLength : botLength;

			float leftHeight = (float)norm(rectPoints[3] - rectPoints[0]);
			float rightHeight = (float)norm(rectPoints[2] - rectPoints[1]);
			float panelHeightPixels = leftHeight < rightHeight ? leftHeight : rightHeight;

			string dimensionDisplayPixels = "Pixels:\nWidth: " + to_string(panelWidthPixels) + " pixels\nHeight: " + to_string(panelHeightPixels) + " pixels";
			// ShowMessage(dimensionDisplayPixels);
			if (m_conversionRate)
			{
				float panelWidthReal = panelWidthPixels / m_conversionRate;
				float panelHeightReal = panelHeightPixels / m_conversionRate;
				string dimensionDisplayActual = "Actual:\nWidth: " + to_string(panelWidthReal) + " cm\nHeight: " + to_string(panelHeightReal) + " cm";
				ShowMessage(dimensionDisplayActual);
			}

		}

		if (showImg){
			namedWindow("Intersections", CV_WINDOW_KEEPRATIO);
			imshow("Intersections", image);
		}
		/////////////////////////////////////////////////////////////
		// End of Computing the intersection from the lines detected
		/////////////////////////////////////////////////////////////
	return edges;
}
Пример #27
0
bool EncryptedTMXLayer::initWithInfo(cocos2d::TMXTilesetInfo *tilesetInfo, cocos2d::TMXLayerInfo *layerInfo, cocos2d::TMXMapInfo *mapInfo, const std::string &encryptionKey)
{
    // XXX: is 35% a good estimate ?
    Size size = layerInfo->_layerSize;
    float totalNumberOfTiles = size.width * size.height;
    float capacity = totalNumberOfTiles * 0.35f + 1; // 35 percent is occupied ?

    this->_encryptionKey = encryptionKey;
    this->_encryptor = FileEncryptor::create(encryptionKey.c_str());
    this->_encryptor->retain();

    Texture2D *texture = nullptr;
    if( tilesetInfo )
    {
        // decrypt first, compatible with Android
        const std::string &resourcePath = FileUtils::getInstance()->fullPathForFilename(tilesetInfo->_sourceImage);
        int outSize = 0;
        unsigned char *data = this->_encryptor->decrypt(resourcePath, &outSize);
        Image *pImage = new Image();
        bool bRet = pImage->initWithImageData(data, outSize);
        if (!bRet)
        {
            return false;
        }

        texture = Director::getInstance()->getTextureCache()->addImage(pImage, resourcePath);
        free(data);
    }

    if (SpriteBatchNode::initWithTexture(texture, static_cast<ssize_t>(capacity)))
    {
        // layerInfo
        _layerName = layerInfo->_name;
        _layerSize = size;
        _tiles = layerInfo->_tiles;
        _opacity = layerInfo->_opacity;
        setProperties(layerInfo->getProperties());
        _contentScaleFactor = Director::getInstance()->getContentScaleFactor();

        // tilesetInfo
        _tileSet = tilesetInfo;
        CC_SAFE_RETAIN(_tileSet);

        // mapInfo
        _mapTileSize = mapInfo->getTileSize();
        _layerOrientation = mapInfo->getOrientation();

        // offset (after layer orientation is set);
        Point offset = this->calculateLayerOffset(layerInfo->_offset);
        this->setPosition(CC_POINT_PIXELS_TO_POINTS(offset));

        _atlasIndexArray = ccCArrayNew(totalNumberOfTiles);

        this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(Size(_layerSize.width * _mapTileSize.width, _layerSize.height * _mapTileSize.height)));

        _useAutomaticVertexZ = false;
        _vertexZvalue = 0;

        return true;
    }
    return false;
}
Пример #28
0
///////////////////////////////////////////////////////
// Panel::PixelsToLength() 
//  Description: Not currently used: Calculates the
// ratio of cm to pixels from one checkerboard image
///////////////////////////////////////////////////////
void Panel::PixelsToLength(string sImgPath)
{
	cout << "Pixels to Length" << endl << endl;
	m_pPanel->m_Image = imread(sImgPath);

	Point2f corner1;
	Point2f corner2;
	Point2f corner3;
	Point2f corner4;

	bool found = false;

	found = findChessboardCorners(m_pPanel->m_Image, Size(9, 6), m_pPanel->corners,
		CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK | CALIB_CB_NORMALIZE_IMAGE);

	Mat imgGray;
	cvtColor(m_pPanel->m_Image, imgGray, COLOR_BGR2GRAY);
	cornerSubPix(imgGray, m_pPanel->corners, Size(11, 11), Size(-1, -1),
		TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));

	corner1.x = m_pPanel->corners[45].x;
	corner1.y = m_pPanel->corners[45].y;

	corner2.x = m_pPanel->corners[0].x;
	corner2.y = m_pPanel->corners[0].y;

	corner3.x = m_pPanel->corners[8].x;
	corner3.y = m_pPanel->corners[8].y;

	corner4.x = m_pPanel->corners[53].x;
	corner4.y = m_pPanel->corners[53].y;

	// Draw rectangle around checkerboard

	line(m_pPanel->m_Image, corner1, corner2, CV_RGB(0, 0, 255), 2);
	line(m_pPanel->m_Image, corner2, corner3, CV_RGB(0, 0, 255), 2);
	line(m_pPanel->m_Image, corner3, corner4, CV_RGB(0, 0, 255), 2);
	line(m_pPanel->m_Image, corner4, corner1, CV_RGB(0, 0, 255), 2);

	circle(m_pPanel->m_Image, corner1, 10, CV_RGB(0, 0, 255), 2);
	circle(m_pPanel->m_Image, corner2, 10, CV_RGB(0, 255, 0), 2);
	circle(m_pPanel->m_Image, corner3, 10, CV_RGB(255, 0, 0), 2);
	circle(m_pPanel->m_Image, corner4, 10, CV_RGB(100, 100, 100), 2);

	double pixel_length = 0;
	double pixel_width = 0;

	double pixel_width1 = norm(corner1 - corner2);
	double pixel_length1 = norm(corner2 - corner3);
	double pixel_width2 = norm(corner3 - corner4);
	double pixel_length2 = norm(corner4 - corner1);

	if (pixel_length1 >= pixel_length2)
		pixel_length = pixel_length1;
	else 
		pixel_length = pixel_length2;

	if (pixel_width1 >= pixel_width2)
		pixel_width = pixel_width1;
	else
		pixel_width = pixel_width2;


	double ratio = (m_pPanel->m_boardLength - 1.0) / (m_pPanel->m_boardWidth - 1.0);

	if (pixel_length >= (pixel_width * ratio)){
		m_pPanel->m_cmPerPixel = (m_pPanel->m_squareSize * (float)(m_pPanel->m_boardLength - 1)) / pixel_length;
	}
	else
		m_pPanel->m_cmPerPixel = (m_pPanel->m_squareSize * (float)(m_pPanel->m_boardWidth - 1)) / pixel_width;

	cout << "cm per pixel : " << m_pPanel->m_cmPerPixel << endl;

	// Perspective Transform
	//	double ratio = 8.0 / 5.0;
	//	double length = ratio * pixel_width;
	//
	//	vector<Point2f> panel_pts;
	//	vector<Point2f> rect_pts;
	//	panel_pts.push_back(corner1);
	//	panel_pts.push_back(corner2);
	//	panel_pts.push_back(corner3);
	//	panel_pts.push_back(corner4);
	//	rect_pts.push_back(Point2f(0, 0));
	//	rect_pts.push_back(Point2f((float)width, 0));
	//	rect_pts.push_back(Point2f((float)width, (float)length));
	//	rect_pts.push_back(Point2f(0, (float)length));
	//
	//	// Draw new rectangle
	//	line(m_pPanel->m_Image, rect_pts[0], rect_pts[1], CV_RGB(255, 0, 0), 2);
	//	line(m_pPanel->m_Image, rect_pts[1], rect_pts[2], CV_RGB(255, 0, 0), 2);
	//	line(m_pPanel->m_Image, rect_pts[2], rect_pts[3], CV_RGB(255, 0, 0), 2);
	//	line(m_pPanel->m_Image, rect_pts[3], rect_pts[0], CV_RGB(255, 0, 0), 2);
	//
	//	// Perspective Transorm
	//	Mat transmtx = getPerspectiveTransform(panel_pts, rect_pts);
	//	int offsetSize = 500;
	//	Mat transformed = Mat::zeros(m_pPanel->m_Image.cols + offsetSize, m_pPanel->m_Image.rows + offsetSize, CV_8UC3);
	//	warpPerspective(m_pPanel->m_Image, transformed, transmtx, transformed.size());
	//
	////	Mat subImg(transformed, Rect(corner1.x, corner1.y, width, length));
	//
	//	namedWindow("Original", WINDOW_NORMAL);
	//	imshow("Original", m_pPanel->m_Image);
	//	namedWindow("Warped", WINDOW_AUTOSIZE);
	//	imshow("Warped", transformed);
}
Пример #29
0
//
//  lifeObj.cpp
//  Card
//
//  Created by cyj on 3/8/14.
//
//

#include "lifeObj.h"
Size lifeObj::activeRange = Size(0, 0);

Sprite* lifeObj::map = NULL;

void lifeObj::createLifeObj(const char* file, const char* name){
    createBaseObj(file, name);
}

void lifeObj::turnAround(){
    if(dir == EDIR_FORWARD){
        rootObj->setScaleX(-1);
        dir = EDIR_BACKWARD;
    }else{
        rootObj->setScaleX(1);
        dir = EDIR_FORWARD;
    }
}

void lifeObj::actionJump(){
    //jump->setVisible(true);
    
    //int distance = 40;
Пример #30
0
void LoadingBar::setScale9Scale()
{
    float width = (float)(_percent) / 100.0f * _totalLength;
    _barRenderer->setPreferredSize(Size(width, _contentSize.height));
}