/*
  public callable function
  to apply image effects set the getters on this class
*/
cv::Mat VideoProcessing::process(cv::Mat &frame) {
    // save reference to the current frame, do NOT copy it into the memory
    this->frame = frame;

    if (picGreyscale == true) {
        convertFrame2Grey();
    }

    if (picInvert == true) {
        invertFrame();
    }

    if (picFlip == true) {
        flipFrame();
    }

    if (picRotateAngle != 0) {
        rotateFrame();
    }

    if (picEqualize == true) {
        equalizeFrame();
    }

    if (picSharpen == true) {
        sharpenFrame();
    }

    if (picCrop == true) {
        cropFrame();
    }


    return this->frame;
}
Пример #2
0
/**
 * Detect objects using cascade detection of haar-wavelets (haar cascade).
 * A variant of Viola-Jones face detection framework.
 *
 * \param currframe Frame that one wants to detect objects.
 * 
 * \param detectAfterRot Whether to rotate currframe by small angles
 * during detection phase. Currently detection is done with haar cascade
 * which is not rotation invariant (can not detect an object if it is 
 * presented rotated). Haar cascade could potentially detect object
 * rotated by a very small angle (+/-15 degrees). Do detection on rotated
 * frames and the straight frame in order to detect the object in
 * much more angular variations.
 */
std::vector<cv::Rect>
ObjDetTrack::haarCascadeDetect(const cv::Mat& currframe, bool detectAfterRot)
{
  cv::Mat frame_gray;
  bool presuccess = detectPreProcess(currframe, frame_gray);
  if(!presuccess){
    return std::vector<cv::Rect>();
  }

  //put all detection results here
  std::vector<cv::Rect> detResult;
  
  //simple straight (no rotation) cascade face/object detection
  std::vector<cv::Rect> straightDetResult = runAllCascadeOnFrame(frame_gray, 2, cv::Size(20*shrinkratio,20*shrinkratio));
  //std::cout<<"detected =="<<(int)straightDetResult.size()<<"== straight"<<std::endl;
  detResult.insert(detResult.end(), straightDetResult.begin(), straightDetResult.end());

  //implements detection after small angle rotations here. Could be really slow
  //Maybe only do this if no straight detResults
  if(detectAfterRot){// && detResult.size() == 0){
    std::vector<double> rotAngles;
    rotAngles.push_back(-30);
    rotAngles.push_back(30);

    for(uint32_t ang_ind=0; ang_ind<rotAngles.size(); ang_ind++){
      cv::Mat frameAfterRot;
      cv::Mat revRotM = rotateFrame(frame_gray, frameAfterRot, rotAngles[ang_ind]);
      std::vector<cv::Rect> rotDetResult = runAllCascadeOnFrame(frameAfterRot, 2, cv::Size(20*shrinkratio,20*shrinkratio));

      std::ostringstream strs;
      strs << rotAngles[ang_ind];
      std::string anglestr = strs.str();
      //std::cout<<"detected =="<<rotDetResult.size()<<"== sideways angle "<<rotAngles[ang_ind]<<std::endl;

      std::vector<cv::Rect> revRotDetResult = revRotOnRects(rotDetResult, revRotM, frame_gray.size());

      detResult.insert(detResult.end(), revRotDetResult.begin(), revRotDetResult.end());
    }
  }

  //eliminate duplicates/overlapping detection
  //they are defined as detection that are overlapping >50% area with other detection rectangles
  removeOverlapWindows(detResult);
  //std::cout<<"=post overlap elimination: detected "<<detResult.size()<<" faces/objects"<<std::endl;

  //reverse downsampling of image, by resizing detection rectangles/windows
  for(uint32_t i=0; i<detResult.size(); i++){
    resizeRect(detResult[i], 1/shrinkratio, 1/shrinkratio);
  }

  return detResult;
}
bool EmulatedQemuCameraDevice::inWorkerThread()
{
    /* Wait till FPS timeout expires, or thread exit message is received. */
    WorkerThread::SelectRes res =
        getWorkerThread()->Select(-1, 1000000 / mEmulatedFPS);
    if (res == WorkerThread::EXIT_THREAD) {
        LOGV("%s: Worker thread has been terminated.", __FUNCTION__);
        return false;
    }

    /* Lets see if we need to generate a new frame. */
    if ((systemTime(SYSTEM_TIME_MONOTONIC) - mLastRedrawn) >= mRedrawAfter) {
        /*
         * Time to generate a new frame.
         */

#if EFCD_ROTATE_FRAME
        LOGV("%s: calld frame_type = rotateFrame():%d", __FUNCTION__, frame_type);
        const int frame_type = rotateFrame();
        switch (frame_type) {
            case 0:
                drawCheckerboard();
                break;
            case 1:
                drawStripes();
                break;
            case 2:
                drawSolid(mCurrentColor);
                break;
        }
#else
        /* Draw the checker board. */
        LOGV("%s: calld drawCheckerboard()", __FUNCTION__);
        drawCheckerboard();

#endif  // EFCD_ROTATE_FRAME

        mLastRedrawn = systemTime(SYSTEM_TIME_MONOTONIC);
    }

    /* Timestamp the current frame, and notify the camera HAL about new frame. */
    mCurFrameTimestamp = systemTime(SYSTEM_TIME_MONOTONIC);

    LOGV("%s: calld mCameraHAL->onNextFrameAvailable(mCurrentFrame:%p", __FUNCTION__,mCurrentFrame);
    mCameraHAL->onNextFrameAvailable(mCurrentFrame, mCurFrameTimestamp, this);

    return true;
}
Пример #4
0
void MainGui::dispatchrotate(bool clockwise) {
	if(currenthdr==NULL)
		return;
	rotateccw->setEnabled(false);
	rotatecw->setEnabled(false);
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
	pfs::Frame *rotated=rotateFrame(currenthdr->getHDRPfsFrame(),clockwise);
	//updateHDR() method takes care of deleting its previous pfs::Frame* buffer.
	currenthdr->updateHDR(rotated);
	if (! currenthdr->NeedsSaving) {
		currenthdr->NeedsSaving=true;
		currenthdr->setWindowTitle(currenthdr->windowTitle().prepend("(*) "));
	}
	QApplication::restoreOverrideCursor();
	rotateccw->setEnabled(true);
	rotatecw->setEnabled(true);
}