Exemplo n.º 1
0
	bool View::traceWorld(int x, int y, Vector3& result, int part) {
		if (selectRegion(Rect(x-1, y-1, 3, 3), part, result)) {
			return true;
		}

		Plane ground(0, 0, 1, 0);
		Vector3 start = m_camera.screenToWorld(Vector3(x, y, -1));
		Vector3 end = m_camera.screenToWorld(Vector3(x, y, 1));
		Vector3 dir = (end - start).getNormalized();
		float scale;

		bool v = ground.rayIntersection(start, dir, scale);

		if (!v)
			return false;

		result = start + dir * scale;

		if (m_context->getState()->isSnapToGrid) {
			result = Internal::snap(result, m_context->getState()->snapToGrid);
		}

		m_context->getState()->setTransformState(false, false, result);

		return true;
	}
//==============================================================================
void CodeEditorComponent::mouseDown (const MouseEvent& e)
{
    newTransaction();
    dragType = notDragging;

    if (e.mods.isPopupMenu())
    {
        setMouseCursor (MouseCursor::NormalCursor);

        if (getHighlightedRegion().isEmpty())
        {
            CodeDocument::Position start, end;
            document.findTokenContaining (getPositionAt (e.x, e.y), start, end);

            if (start.getPosition() < end.getPosition())
                selectRegion (start, end);
        }

        PopupMenu m;
        m.setLookAndFeel (&getLookAndFeel());
        addPopupMenuItems (m, &e);

        m.showMenuAsync (PopupMenu::Options(),
                         ModalCallbackFunction::forComponent (codeEditorMenuCallback, this));
    }
    else
    {
        beginDragAutoRepeat (100);
        moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
    }
}
bool CodeEditorComponent::selectAll()
{
    newTransaction();
    selectRegion (CodeDocument::Position (document, std::numeric_limits<int>::max(),
                                          std::numeric_limits<int>::max()),
                  CodeDocument::Position (document, 0, 0));
    return true;
}
void GenericCodeEditorComponent::findNext (bool forwards, bool skipCurrentSelection)
{
	const Range<int> highlight (getHighlightedRegion());
	const CodeDocument::Position startPos (getDocument(), skipCurrentSelection ? highlight.getEnd()
		: highlight.getStart());
	int lineNum = startPos.getLineNumber();
	int linePos = startPos.getIndexInLine();

	const int totalLines = getDocument().getNumLines();
	const String searchText (getSearchString());
	const bool caseSensitive = isCaseSensitiveSearch();

	for (int linesToSearch = totalLines; --linesToSearch >= 0;)
	{
		String line (getDocument().getLine (lineNum));
		int index;

		if (forwards)
		{
			index = caseSensitive ? line.indexOf (linePos, searchText)
				: line.indexOfIgnoreCase (linePos, searchText);
		}
		else
		{
			if (linePos >= 0)
				line = line.substring (0, linePos);

			index = caseSensitive ? line.lastIndexOf (searchText)
				: line.lastIndexOfIgnoreCase (searchText);
		}

		if (index >= 0)
		{
			const CodeDocument::Position p (getDocument(), lineNum, index);
			selectRegion (p, p.movedBy (searchText.length()));
			break;
		}

		if (forwards)
		{
			linePos = 0;
			lineNum = (lineNum + 1) % totalLines;
		}
		else
		{
			if (--lineNum < 0)
				lineNum = totalLines - 1;

			linePos = -1;
		}
	}
}
Exemplo n.º 5
0
void SeedGLWidget::mouseReleaseEvent(QMouseEvent *e)
{
	GLWidget::mouseReleaseEvent(e);

	Point pt = new double [2];
	pt[0] = e->x();
	pt[1] = e->y();
	_penTrack.push_back(pt);

	selectRegion();
	_bDrawing = false;
	repaint();
}
void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
{
    CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
    CodeDocument::Position tokenEnd (tokenStart);

    if (e.getNumberOfClicks() > 2)
        document.findLineContaining (tokenStart, tokenStart, tokenEnd);
    else
        document.findTokenContaining (tokenStart, tokenStart, tokenEnd);

    selectRegion (tokenStart, tokenEnd);
    dragType = notDragging;
}
bool CodeEditorComponent::moveCaretRight (const bool moveInWholeWordSteps, const bool selecting)
{
    newTransaction();

    if (selecting && dragType == notDragging)
    {
        selectRegion (CodeDocument::Position (selectionStart), CodeDocument::Position (selectionEnd));
        dragType = draggingSelectionEnd;
    }

    if (isHighlightActive() && ! (selecting || moveInWholeWordSteps))
    {
        moveCaretTo (selectionEnd, false);
        return true;
    }

    if (moveInWholeWordSteps)
        moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
    else
        moveCaretTo (caretPos.movedBy (1), selecting);

    return true;
}
Exemplo n.º 8
0
bool ompl::control::Syclop::solve(const base::PlannerTerminationCondition& ptc)
{
    checkValidity();
    if (!graphReady_)
    {
        numMotions_ = 0;
        setupRegionEstimates();
        setupEdgeEstimates();
        graphReady_ = true;
    }
    while (const base::State* s = pis_.nextStart())
    {
        const int region = decomp_->locateRegion(s);
        startRegions_.insert(region);
        Motion* startMotion = addRoot(s);
        graph_[boost::vertex(region,graph_)].motions.push_back(startMotion);
        ++numMotions_;
        updateCoverageEstimate(graph_[boost::vertex(region,graph_)], s);
    }
    if (startRegions_.empty())
    {
        msg_.error("There are no valid start states");
        return false;
    }

    //We need at least one valid goal sample so that we can find the goal region
    if (goalRegions_.empty())
    {
        if (const base::State* g = pis_.nextGoal(ptc))
            goalRegions_.insert(decomp_->locateRegion(g));
        else
        {
            msg_.error("Unable to sample a valid goal state");
            return false;
        }
    }

    msg_.inform("Starting with %u states", numMotions_);

    std::vector<Motion*> newMotions;
    const Motion* solution = NULL;
    base::Goal* goal = pdef_->getGoal().get();
    double goalDist = std::numeric_limits<double>::infinity();
    bool solved = false;
    while (!ptc() && !solved)
    {
        const int chosenStartRegion = startRegions_.sampleUniform();
        int chosenGoalRegion = -1;

        // if we have not sampled too many goal regions already
        if (pis_.haveMoreGoalStates() && goalRegions_.size() < numMotions_/2)
        {
            if (const base::State* g = pis_.nextGoal())
            {
                chosenGoalRegion = decomp_->locateRegion(g);
                goalRegions_.insert(chosenGoalRegion);
            }
        }
        if (chosenGoalRegion == -1)
            chosenGoalRegion = goalRegions_.sampleUniform();

        computeLead(chosenStartRegion, chosenGoalRegion);
        computeAvailableRegions();
        for (int i = 0; i < numRegionExpansions_ && !solved && !ptc(); ++i)
        {
            const int region = selectRegion();
            bool improved = false;
            for (int j = 0; j < numTreeSelections_ && !solved && !ptc(); ++j)
            {
                newMotions.clear();
                selectAndExtend(graph_[boost::vertex(region,graph_)], newMotions);
                for (std::vector<Motion*>::const_iterator m = newMotions.begin(); m != newMotions.end() && !ptc(); ++m)
                {
                    Motion* motion = *m;
                    double distance;
                    solved = goal->isSatisfied(motion->state, &distance);
                    if (solved)
                    {
                        goalDist = distance;
                        solution = motion;
                        break;
                    }

                    // Check for approximate (best-so-far) solution
                    if (distance < goalDist)
                    {
                        goalDist = distance;
                        solution = motion;
                    }
                    const int newRegion = decomp_->locateRegion(motion->state);
                    graph_[boost::vertex(newRegion,graph_)].motions.push_back(motion);
                    ++numMotions_;
                    Region& newRegionObj = graph_[boost::vertex(newRegion, graph_)];
                    improved |= updateCoverageEstimate(newRegionObj, motion->state);
                    if (newRegion != region)
                    {
                        // If this is the first time the tree has entered this region, add the region to avail
                        if (newRegionObj.motions.size() == 1)
                            availDist_.add(newRegion, newRegionObj.weight);
                        /* If the tree crosses an entire region and creates an edge (u,v) for which Proj(u) and Proj(v) are non-neighboring regions,
                            then we do not update connection estimates. This is because Syclop's shortest-path lead computation only considers neighboring regions. */
                        if (regionsToEdge_.count(std::pair<int,int>(region, newRegion)) > 0)
                        {
                            Adjacency* adj = regionsToEdge_[std::pair<int,int>(region,newRegion)];
                            adj->empty = false;
                            ++adj->numSelections;
                            improved |= updateConnectionEstimate(graph_[boost::vertex(region,graph_)], newRegionObj, motion->state);
                        }
                    }
                }
            }
            if (!improved && rng_.uniform01() < probAbandonLeadEarly_)
                break;
        }
    }
    bool addedSolution = false;
    if (solution != NULL)
    {
        std::vector<const Motion*> mpath;
        while (solution != NULL)
        {
            mpath.push_back(solution);
            solution = solution->parent;
        }
        PathControl* path = new PathControl(si_);
        for (int i = mpath.size()-1; i >= 0; --i)
            if (mpath[i]->parent)
                path->append(mpath[i]->state, mpath[i]->control, mpath[i]->steps * siC_->getPropagationStepSize());
            else
                path->append(mpath[i]->state);
        goal->addSolutionPath(base::PathPtr(path), !solved, goalDist);
        addedSolution = true;
    }
    return addedSolution;
}
Exemplo n.º 9
0
Arquivo: Syclop.cpp Projeto: ompl/ompl
ompl::base::PlannerStatus ompl::control::Syclop::solve(const base::PlannerTerminationCondition &ptc)
{
    checkValidity();
    if (!graphReady_)
    {
        numMotions_ = 0;
        setupRegionEstimates();
        setupEdgeEstimates();
        graphReady_ = true;
    }
    while (const base::State *s = pis_.nextStart())
    {
        const int region = decomp_->locateRegion(s);
        startRegions_.insert(region);
        Motion *startMotion = addRoot(s);
        graph_[boost::vertex(region, graph_)].motions.push_back(startMotion);
        ++numMotions_;
        updateCoverageEstimate(graph_[boost::vertex(region, graph_)], s);
    }
    if (startRegions_.empty())
    {
        OMPL_ERROR("%s: There are no valid start states", getName().c_str());
        return base::PlannerStatus::INVALID_START;
    }

    // We need at least one valid goal sample so that we can find the goal region
    if (goalRegions_.empty())
    {
        if (const base::State *g = pis_.nextGoal(ptc))
            goalRegions_.insert(decomp_->locateRegion(g));
        else
        {
            OMPL_ERROR("%s: Unable to sample a valid goal state", getName().c_str());
            return base::PlannerStatus::INVALID_GOAL;
        }
    }

    OMPL_INFORM("%s: Starting planning with %u states already in datastructure", getName().c_str(), numMotions_);

    std::vector<Motion *> newMotions;
    const Motion *solution = nullptr;
    base::Goal *goal = pdef_->getGoal().get();
    double goalDist = std::numeric_limits<double>::infinity();
    bool solved = false;
    while (!ptc && !solved)
    {
        const int chosenStartRegion = startRegions_.sampleUniform();
        int chosenGoalRegion = -1;

        // if we have not sampled too many goal regions already
        if (pis_.haveMoreGoalStates() && goalRegions_.size() < numMotions_ / 2)
        {
            if (const base::State *g = pis_.nextGoal())
            {
                chosenGoalRegion = decomp_->locateRegion(g);
                goalRegions_.insert(chosenGoalRegion);
            }
        }
        if (chosenGoalRegion == -1)
            chosenGoalRegion = goalRegions_.sampleUniform();

        leadComputeFn(chosenStartRegion, chosenGoalRegion, lead_);
        computeAvailableRegions();
        for (int i = 0; i < numRegionExpansions_ && !solved && !ptc; ++i)
        {
            const int region = selectRegion();
            bool improved = false;
            for (int j = 0; j < numTreeSelections_ && !solved && !ptc; ++j)
            {
                newMotions.clear();
                selectAndExtend(graph_[boost::vertex(region, graph_)], newMotions);
                for (std::vector<Motion *>::const_iterator m = newMotions.begin(); m != newMotions.end() && !ptc; ++m)
                {
                    Motion *motion = *m;
                    double distance;
                    solved = goal->isSatisfied(motion->state, &distance);
                    if (solved)
                    {
                        goalDist = distance;
                        solution = motion;
                        break;
                    }

                    // Check for approximate (best-so-far) solution
                    if (distance < goalDist)
                    {
                        goalDist = distance;
                        solution = motion;
                    }
                    const int newRegion = decomp_->locateRegion(motion->state);
                    graph_[boost::vertex(newRegion, graph_)].motions.push_back(motion);
                    ++numMotions_;
                    Region &newRegionObj = graph_[boost::vertex(newRegion, graph_)];
                    improved |= updateCoverageEstimate(newRegionObj, motion->state);
                    /* If tree has just crossed from one region to its neighbor,
                       update the connection estimates. If the tree has crossed an entire region,
                       then region and newRegion are not adjacent, and so we do not update estimates. */
                    if (newRegion != region && regionsToEdge_.count(std::pair<int, int>(region, newRegion)) > 0)
                    {
                        Adjacency *adj = regionsToEdge_[std::pair<int, int>(region, newRegion)];
                        adj->empty = false;
                        ++adj->numSelections;
                        improved |= updateConnectionEstimate(graph_[boost::vertex(region, graph_)], newRegionObj,
                                                             motion->state);
                    }

                    /* If this region already exists in availDist, update its weight. */
                    if (newRegionObj.pdfElem != nullptr)
                        availDist_.update(newRegionObj.pdfElem, newRegionObj.weight);
                    /* Otherwise, only add this region to availDist
                       if it already exists in the lead. */
                    else if (std::find(lead_.begin(), lead_.end(), newRegion) != lead_.end())
                    {
                        PDF<int>::Element *elem = availDist_.add(newRegion, newRegionObj.weight);
                        newRegionObj.pdfElem = elem;
                    }
                }
            }
            if (!improved && rng_.uniform01() < probAbandonLeadEarly_)
                break;
        }
    }
    bool addedSolution = false;
    if (solution != nullptr)
    {
        std::vector<const Motion *> mpath;
        while (solution != nullptr)
        {
            mpath.push_back(solution);
            solution = solution->parent;
        }
        auto path(std::make_shared<PathControl>(si_));
        for (int i = mpath.size() - 1; i >= 0; --i)
            if (mpath[i]->parent != nullptr)
                path->append(mpath[i]->state, mpath[i]->control, mpath[i]->steps * siC_->getPropagationStepSize());
            else
                path->append(mpath[i]->state);
        pdef_->addSolutionPath(path, !solved, goalDist, getName());
        addedSolution = true;
    }
    return addedSolution ? base::PlannerStatus::EXACT_SOLUTION : base::PlannerStatus::TIMEOUT;
}
void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
{
    selectRegion (CodeDocument::Position (document, newRange.getStart()),
                  CodeDocument::Position (document, newRange.getEnd()));
}
//------------------------------------------------------------------------------------------------------
void QOpencvProcessor::faceProcess(const cv::Mat &input)
{
    cv::Mat output;
    if(f_fill)
        output = input;
    else
        output = input.clone();

    cv::Mat gray; // Create an instance of cv::Mat for temporary image storage
    cv::cvtColor(input, gray, CV_BGR2GRAY);
    cv::equalizeHist(gray, gray);
    std::vector<cv::Rect> faces_vector;

    m_classifier.detectMultiScale(gray, faces_vector, 1.1, 7, cv::CASCADE_FIND_BIGGEST_OBJECT, cv::Size(OBJECT_MINSIZE, OBJECT_MINSIZE)); // Detect faces (list of flags CASCADE_DO_CANNY_PRUNING, CASCADE_DO_ROUGH_SEARCH, CASCADE_FIND_BIGGEST_OBJECT, CASCADE_SCALE_IMAGE )

    if(faces_vector.size() == 0) {
        m_emptyFrames++;
        if(m_emptyFrames > FRAMES_WITHOUT_FACE_TRESHOLD)
            setAverageFaceRect(0, 0, 0, 0);
    } else {
        m_emptyFrames = 0;
        enrollFaceRect(faces_vector[0]);
    }
    cv::Rect face = getAverageFaceRect();

    unsigned int X = face.x; // the top-left corner horizontal coordinate of future rectangle
    unsigned int Y = face.y; // the top-left corner vertical coordinate of future rectangle
    unsigned int rectwidth = face.width; //...
    unsigned int rectheight = face.height; //...
    unsigned long red = 0; // an accumulator for red color channel
    unsigned long green = 0; // an accumulator for green color channel
    unsigned long blue = 0; // an accumulator for blue color channel
    unsigned int dX = rectwidth/16;
    unsigned int dY = rectheight/30;
    unsigned long area = 0;

    if(face.area() > 10000)
    {
        for(int i = 0; i < 256; i++)
            v_temphist[i] = 0;
        cv::Mat blurRegion(output, face);
        cv::blur(blurRegion, blurRegion, cv::Size(m_blurSize, m_blurSize));
        m_ellipsRect = cv::Rect(X + dX, Y - 6 * dY, rectwidth - 2 * dX, rectheight + 6 * dY);
        X = m_ellipsRect.x;
        rectwidth = m_ellipsRect.width;
        unsigned char *p; // this pointer will be used to store adresses of the image rows
        unsigned char tempBlue;
        unsigned char tempRed;
        unsigned char tempGreen;
        if(output.channels() == 3)
        {
            if(m_skinFlag)
            {
                if(f_fill){
                    for(unsigned int j = Y; j < Y + rectheight; j++) // it is lucky that unsigned int saves from out of image memory cells processing from image top bound, but not from bottom where you should check this issue explicitly
                    {
                        p = output.ptr(j); //takes pointer to beginning of data on row
                        for(unsigned int i = X; i < X + rectwidth; i++)
                        {
                            tempBlue = p[3*i];
                            tempGreen = p[3*i+1];
                            tempRed = p[3*i+2];
                            if( isSkinColor(tempRed, tempGreen, tempBlue) && isInEllips(i, j)) {
                                area++;
                                blue += tempBlue;
                                green += tempGreen;
                                red += tempRed;
                                //p[3*i] = 255;
                                //p[3*i+1] %= LEVEL_SHIFT;
                                p[3*i+2] %= LEVEL_SHIFT;
                                v_temphist[tempGreen]++;
                            }
                        }
                    }
                } else {
                    for(unsigned int j = Y; j < Y + rectheight; j++) // it is lucky that unsigned int saves from out of image memory cells processing from image top bound, but not from bottom where you should check this issue explicitly
                    {
                        p = output.ptr(j); //takes pointer to beginning of data on row
                        for(unsigned int i = X; i < X + rectwidth; i++)
                        {
                            tempBlue = p[3*i];
                            tempGreen = p[3*i+1];
                            tempRed = p[3*i+2];
                            if( isSkinColor(tempRed, tempGreen, tempBlue) && isInEllips(i, j)) {
                                area++;
                                blue += tempBlue;
                                green += tempGreen;
                                red += tempRed;
                                v_temphist[tempGreen]++;
                            }
                        }
                    }
                }
            } else {
                for(unsigned int j = Y; j < Y + rectheight; j++)
                {
                    p = output.ptr(j); //takes pointer to beginning of data on row
                    for(unsigned int i = X; i < X + rectwidth; i++)
                    {
                        blue += p[3*i];
                        green += p[3*i+1];
                        red += p[3*i+2];
                        if(f_fill)  {
                            //p[3*i] = 255;
                            //p[3*i+1] %= LEVEL_SHIFT;
                            p[3*i+2] %= LEVEL_SHIFT;
                        }
                        v_temphist[p[3*i+1]]++;
                    }
                }
                area = rectwidth*rectheight;
            }
        } else {
            for(unsigned int j = Y; j < Y + rectheight; j++)
            {
                p = output.ptr(j);//pointer to beginning of data on rows
                for(unsigned int i = X; i < X + rectwidth; i++)
                {
                    green += p[i];
                    //Uncomment if want to see the enrolled domain on image
                    if(f_fill)  {
                        p[i] %= LEVEL_SHIFT;
                    }
                    v_temphist[p[i]]++;
                }
            }
            blue = green;
            red = green;
            area = rectwidth*rectheight;
        }
    }


    //-----end of if(faces_vector.size() != 0)-----
    m_framePeriod = ((double)cv::getTickCount() -  m_timeCounter)*1000.0 / cv::getTickFrequency();
    m_timeCounter = cv::getTickCount();
    if(area > 1000)
    {
        if(!f_fill)
            cv::rectangle( cv::Mat(input), face, cv::Scalar(15,15,250),1,CV_AA);

        emit dataCollected(red, green, blue, area, m_framePeriod);

        unsigned int mass = 0;
        for(int i = 0; i < 256; i++)
            mass += v_temphist[i];
        if(mass > 0)
        for(int i = 0; i < 256; i++)
            v_hist[i] = (qreal)v_temphist[i]/mass;
        emit histUpdated(v_hist, 256);
    }
    else
    {
        if(m_classifier.empty())
            emit selectRegion( QT_TRANSLATE_NOOP("QImageWidget", "Load cascade for detection") );
        else
            emit selectRegion( QT_TRANSLATE_NOOP("QImageWidget", "Come closer or change light") );
    }
    emit frameProcessed(input, m_framePeriod, area);
}
void QOpencvProcessor::rectProcess(const cv::Mat &input)
{
    cv::Mat output(input); //Copy constructor
    unsigned int rectwidth = m_cvRect.width;
    unsigned int rectheight = m_cvRect.height;
    unsigned int X = m_cvRect.x;
    unsigned int Y = m_cvRect.y;

    if( (output.rows < (Y + rectheight)) || (output.cols < (X + rectwidth)) )
    {
        rectheight = 0;
        rectwidth = 0;
    }

    unsigned long red = 0;
    unsigned long green = 0;
    unsigned long blue = 0;
    unsigned long area = 0;
    //-------------------------------------------------------------------------
    if((rectheight > 0) && (rectwidth > 0))
    {
        for(int i = 0; i < 256; i++)
            v_temphist[i] = 0;

        cv::Mat blurRegion(output, m_cvRect);
        cv::blur(blurRegion, blurRegion, cv::Size(m_blurSize, m_blurSize));

        unsigned char *p; // a pointer to store the adresses of image rows
        if(output.channels() == 3)
        {
            if(m_seekCalibColors)
            {
                unsigned char tempRed;
                unsigned char tempGreen;
                unsigned char tempBlue;
                for(unsigned int j = Y; j < Y + rectheight; j++)
                {
                    p = output.ptr(j); //takes pointer to beginning of data on rows
                    for(unsigned int i = X; i < X + rectwidth; i++)
                    {
                        tempBlue = p[3*i];
                        tempGreen = p[3*i+1];
                        tempRed = p[3*i+2];
                        if( isCalibColor(tempGreen) && isSkinColor(tempRed, tempGreen, tempBlue) ) {
                            area++;
                            blue += tempBlue;
                            green += tempGreen;
                            red += tempRed;
                            if(f_fill)  {
                                //p[3*i] = 255;
                                //p[3*i+1] %= LEVEL_SHIFT;
                                p[3*i+2] %= LEVEL_SHIFT;
                            }
                            v_temphist[tempGreen]++;
                        }
                    }
                }
            } else {
            if(m_skinFlag)
            {
                unsigned char tempRed;
                unsigned char tempGreen;
                unsigned char tempBlue;
                for(unsigned int j = Y; j < Y + rectheight; j++)
                {
                    p = output.ptr(j); //takes pointer to beginning of data on rows
                    for(unsigned int i = X; i < X + rectwidth; i++)
                    {
                        tempBlue = p[3*i];
                        tempGreen = p[3*i+1];
                        tempRed = p[3*i+2];
                        if( isSkinColor(tempRed, tempGreen, tempBlue)) {
                            area++;
                            blue += tempBlue;
                            green += tempGreen;
                            red += tempRed;
                            if(f_fill)  {
                                //p[3*i] = 255;
                                //p[3*i+1] %= LEVEL_SHIFT;
                                p[3*i+2] %= LEVEL_SHIFT;
                            }
                            v_temphist[tempGreen]++;
                        }
                    }
                }
            }
            else
            {
                for(unsigned int j = Y; j < Y + rectheight; j++)
                {
                    p = output.ptr(j); //takes pointer to beginning of data on rows
                    for(unsigned int i = X; i < X + rectwidth; i++)
                    {
                        blue += p[3*i];
                        green += p[3*i+1];
                        red += p[3*i+2];
                        if(f_fill)  {
                            //p[3*i] = 255;
                            //p[3*i+1] %= LEVEL_SHIFT;
                            p[3*i+2] %= LEVEL_SHIFT;
                        }
                        v_temphist[p[3*i+1]]++;
                    }
                }
                area = rectwidth*rectheight;
            }
            }
        }
        else
        {
            for(unsigned int j = Y; j < Y + rectheight; j++)
            {
                p = output.ptr(j);//pointer to beginning of data on rows
                for(unsigned int i = X; i < X + rectwidth; i++)
                {
                    green += p[i];
                    if(f_fill)  {
                        p[i] %= LEVEL_SHIFT;
                    }
                    v_temphist[p[i]]++;
                }
            }
            area = rectwidth*rectheight;
        }
    }
    //------end of if((rectheight > 0) && (rectwidth > 0))
    m_framePeriod = ((double)cv::getTickCount() -  m_timeCounter)*1000.0 / cv::getTickFrequency();
    m_timeCounter = cv::getTickCount();
    if( area > 0 )
    {
        cv::rectangle( output , m_cvRect, cv::Scalar(15,250,15), 1, CV_AA);
        emit dataCollected(red, green, blue, area, m_framePeriod);

        unsigned int mass = 0;
        for(int i = 0; i < 256; i++)
            mass += v_temphist[i];
        if(mass > 0)
        for(int i = 0; i < 256; i++)
            v_hist[i] = (qreal)v_temphist[i]/mass;
        emit histUpdated(v_hist, 256);

        if(m_calibFlag)
        {
            v_calibValues[m_calibSamples] = (qreal)green/area;
            m_calibMean += v_calibValues[m_calibSamples];
            m_calibSamples++;
            if(m_calibSamples == CALIBRATION_VECTOR_LENGTH)
            {
                m_calibMean /= CALIBRATION_VECTOR_LENGTH;
                m_calibError = 0.0;
                for(quint16 i = 0; i < CALIBRATION_VECTOR_LENGTH; i++)
                {
                    m_calibError += (v_calibValues[i] - m_calibMean)*(v_calibValues[i] - m_calibMean);
                }
                m_calibError = 10 * sqrt( m_calibError /(CALIBRATION_VECTOR_LENGTH - 1) );
                qWarning("mean: %f; error: %f; samples: %d", m_calibMean,m_calibError, m_calibSamples);
                m_calibSamples = 0;
                m_calibFlag = false;
                m_seekCalibColors = true;
                emit calibrationDone(m_calibMean, m_calibError/10, m_calibSamples);
            }
        }
    }
    else
    {
        emit selectRegion( QT_TRANSLATE_NOOP("QImageWidget", "Select region on image" ) );
    }
    emit frameProcessed(output, m_framePeriod, area);
}