Пример #1
0
/**
 * Separate the background from the foreground
 * ie.: Create an 8 bit image where only the foreground of the scene is white
 */
void Scene3DRenderer::processForeground(Camera* camera)
{
	Mat hsv_image;
	cvtColor(camera->getFrame(), hsv_image, CV_BGR2HSV);  // from BGR to HSV color space

	vector<Mat> channels;
	split(hsv_image, channels);  // Split the HSV-channels for further analysis

	// Background subtraction H
	Mat tmp, foreground, background;
	absdiff(channels[0], camera->getBgHsvChannels().at(0), tmp);
	threshold(tmp, foreground, _h_threshold, 255, CV_THRESH_BINARY);

	// Background subtraction S
	absdiff(channels[1], camera->getBgHsvChannels().at(1), tmp);
	threshold(tmp, background, _s_threshold, 255, CV_THRESH_BINARY);
	bitwise_and(foreground, background, foreground);

	// Background subtraction V
	absdiff(channels[2], camera->getBgHsvChannels().at(2), tmp);
	threshold(tmp, background, _v_threshold, 255, CV_THRESH_BINARY);
	bitwise_or(foreground, background, foreground);

	// Remove noise
#ifndef USE_GRAPHCUTS
	// Using Erosion and/or Dilation of the foreground image
#else
	// Using Graph cuts on the foreground image
#endif

	camera->setForegroundImage(foreground);
}
Пример #2
0
int main()
{

	printf("testing +ve numbers...");
	if (absdiff(10, 6) != 4)
		goto fail;
	printf("[ok]\n");

	printf("testing +ve numbers...");
	if (absdiff(10, 16) != 6)
		goto fail;
	printf("[ok]\n");

	printf("testing -ve numbers...");
	if (absdiff(10, -6) != 16)
		goto fail;
	printf("[ok]\n");

	printf("testing -ve numbers...");
	if (absdiff(-5, 3) != 8)
		goto fail;
	printf("[ok]\n");

	printf("testing -ve numbers...");
	if (absdiff(-5, -8) != 3)
		goto fail;
	printf("[ok]\n");

	return 0;
fail:
	printf("[failed]\n");
	return -1;
}
Пример #3
0
	int sobel_argb32_3x3_partial(vbx_uword_t *sobel_out, vbx_uword_t *argb_in, const short image_width,
	                             const short image_height, const short image_pitch, const short renorm)
	{
		VBX::Prefetcher<vbx_uword_t> input(1,image_width,argb_in,argb_in+image_height*image_pitch,image_pitch);
		VBX::Vector<vbx_uword_t> output(image_width);
		VBX::Vector<vbx_uhalf_t>* luma[3];
		luma[0]=new VBX::Vector<vbx_uhalf_t>(image_width);
		luma[1]=new VBX::Vector<vbx_uhalf_t>(image_width);
		luma[2]=new VBX::Vector<vbx_uhalf_t>(image_width);
		VBX::Vector<vbx_uhalf_t> gradient_x(image_width);
		VBX::Vector<vbx_uhalf_t> gradient_y(image_width);
		VBX::Vector<vbx_uhalf_t>* sobel_rows[3];

		sobel_rows[0]=new VBX::Vector<vbx_uhalf_t>(image_width);
		sobel_rows[1]=new VBX::Vector<vbx_uhalf_t>(image_width);
		sobel_rows[2]=new VBX::Vector<vbx_uhalf_t>(image_width);
		input.fetch();
		int rowmod3=0;
		for(int row=0;row<image_height;row++){
			input.fetch();

			VBX::Vector<vbx_uhalf_t>& sobel_top= *sobel_rows[rowmod3];
			VBX::Vector<vbx_uhalf_t>& sobel_bot= *sobel_rows[mod3(rowmod3+2)];
			VBX::Vector<vbx_uhalf_t>& luma_top= *luma[rowmod3];
			VBX::Vector<vbx_uhalf_t>& luma_mid= *luma[mod3(rowmod3+1)];
			VBX::Vector<vbx_uhalf_t>& luma_bot= *luma[mod3(rowmod3+2)];
			rowmod3=mod3(rowmod3+1);
			argb_to_luma8(luma_bot,input[0]);
			sobel_row( sobel_bot ,luma_bot);
			if(row<2){
				continue;
			}

			gradient_y=absdiff(sobel_top,sobel_bot);
			gradient_x=luma_top +luma_bot + luma_mid*2;
			gradient_x[1 upto image_width-1]=absdiff(gradient_x[0 upto image_width-2],gradient_x[2 upto image_width]);

			output=((gradient_x + gradient_y) >> renorm);

			output.cond_move(output>0xFF,0xFF);

			output*=0x010101;

			//write to output buffer, skipping first and last elements
			output[1 upto (image_width -1)].dma_write(sobel_out+(row-1)*image_pitch +1);

		}
		output=0;
		output.dma_write(sobel_out);
		output.dma_write(sobel_out+ (image_height-1)*image_pitch);
		delete luma[0];
		delete luma[1];
		delete luma[2];
		delete sobel_rows[0];
		delete sobel_rows[1];
		delete sobel_rows[2];

		return 0;
	}
Пример #4
0
	int sobel_luma8_3x3(vbx_uword_t *output,
	                    unsigned char *input,
	                    const short image_width,
	                    const short image_height,
	                    const short image_pitch,
	                    const short renorm)
	{
		VBX::Prefetcher<vbx_ubyte_t> luma_in(3,image_width,input,input+image_height*image_pitch,image_pitch);
		VBX::Vector<vbx_uhalf_t> *sobel[3];
		sobel[0]=new VBX::Vector<vbx_uhalf_t>(image_width-2);
		sobel[1]=new VBX::Vector<vbx_uhalf_t>(image_width-2);
		sobel[2]=new VBX::Vector<vbx_uhalf_t>(image_width-2);
		VBX::Vector<vbx_uhalf_t> gradient_x(image_width-2);
		VBX::Vector<vbx_uhalf_t> gradient_y(image_width-2);
		VBX::Vector<vbx_uword_t> row_out(image_width);
		VBX::Vector<vbx_uhalf_t> tmp(image_width);
		if(!tmp.data){
			printf("Out of scratchpad memory\n");
			return -1;
		}
		luma_in.fetch();
		luma_in.fetch();

		sobel_row(*sobel[0],luma_in[0]);
		luma_in.fetch();
		sobel_row(*sobel[1],luma_in[1]);
		//set first row black
		row_out=0;
		row_out.dma_write(output);
		for(int row=0,s_t=0,s_b=2;row<image_height-(3-1);row++,s_t++,s_b++){
			luma_in.fetch();
			//use reference to refer to vectors without copying
			VBX::Vector<vbx_ubyte_t>& luma_top=luma_in[0];
			VBX::Vector<vbx_ubyte_t>& luma_mid=luma_in[1];
			VBX::Vector<vbx_ubyte_t>& luma_bot=luma_in[2];
			if(s_t>=3)s_t=0;//mod 3
			if(s_b>=3)s_b=0;//mod 3
			VBX::Vector<vbx_uhalf_t>& sobel_top=*sobel[s_t];
			VBX::Vector<vbx_uhalf_t>& sobel_bot=*sobel[s_b];

			sobel_row(sobel_bot,luma_bot);

			gradient_y=absdiff(sobel_top,sobel_bot);
			tmp=luma_top+luma_bot+(luma_mid<<1);
			gradient_x=absdiff(tmp,tmp[2 upto image_width]);
			//sum the gradients, normalize and saturate at 255
			row_out[1 upto image_width-1]=(gradient_x+gradient_y)>>renorm;
			row_out.cond_move(row_out>255,255);
			//copy lowest byte into the 2nd and 3rd;
			row_out*=0x10101;
			row_out.dma_write(output+(row+1)*image_pitch);
		}
		//set last row black
		row_out=0;
		row_out.dma_write(output+(image_height-1)*image_width);
		return 0;
	}
Пример #5
0
void Marker::ratePositionMarker(const Image3D& image, PositionMarker& pm) {
    // compute mean J interval for global marker
    unsigned int meanMinJ = 0;
    for (size_t id=0; id<2; ++id) {
        meanMinJ += previousAreas[id].minJ;
    }
    meanMinJ /= 2;
    unsigned int meanMaxJ = 0;
    for (size_t id=0; id<2; ++id) {
        meanMaxJ += previousAreas[id].maxJ;
    }
    meanMaxJ /= 2;

    // feed most properties for PositionMarker (except confidence)
    pm.imageID = image.id;
    pm.x = ( meanMinJ + meanMaxJ ) / 2;
    pm.size = meanMaxJ - meanMinJ;
    pm.minI = previousAreas[0].minI;
    pm.maxI = previousAreas[1].maxI;
    if (isMarkerFound(previousPos)) {
        pm.dx = (int)previousPos.x - (int)pm.x;
        pm.dsize = (int)previousPos.size - (int)pm.size;
    }

    // compute difference with the mean
    unsigned int distMinJ = 0;
    for (size_t id=0; id<2; ++id) {
        distMinJ += absdiff(meanMinJ, previousAreas[id].minJ);
    }
    unsigned int distMaxJ = 0;
    for (size_t id=0; id<2; ++id) {
        distMaxJ += absdiff(meanMaxJ, previousAreas[id].maxJ);
    }

    // compute difference between (mean)width and height
    unsigned int height = pm.maxI - pm.minI;
    unsigned int diffWidthHeight = absdiff(pm.size, height);

    // compute distance from middle of image (depending enemy or not)
    unsigned int distFromMiddle;
    unsigned int imageMiddleHeight = image.height / 2;
    if (isEnemy) {
        distFromMiddle = absdiff(imageMiddleHeight, pm.maxI);
    } else {
        distFromMiddle = absdiff(imageMiddleHeight, pm.minI);
    }

    float confidence_distFromMiddle = 0.05f * (float) distFromMiddle / (float) pm.size;
    float confidence_diffWidthHeight = 0.5f * (float) diffWidthHeight / (float) pm.size;
    //std::cout << "conf_distFromMiddle=" << confidence_distFromMiddle << std::endl;
    //std::cout << "conf_diffWidthHeight=" << confidence_diffWidthHeight << std::endl;
    pm.confidence = 1.f - confidence_distFromMiddle - confidence_diffWidthHeight;
}
Пример #6
0
void channelDist(Mat& hsv, Mat& dist, int hueVal, int channel)
{
	Mat channelImg;
	getChannel(hsv, channelImg, channel);
	if (channel == 0)
	{
		Mat dist1, dist2;
		absdiff(channelImg, hueVal, dist1);
		absdiff(channelImg, hueVal + ((hueVal < 90) ? 180 : -180), dist2);
		min(dist1, dist2, dist);
	}
	else
		absdiff(channelImg, hueVal, dist);
}
Пример #7
0
/* repeatedly calls the function to measure -- argument is iteration
 * count */ 
unsigned measure(int iter)
{
    int i;
    unsigned cmeas,cycles;
    volatile int res = 0;  /* don't let compiler optimize away fn
			    * calls */
    
    res += absdiff(0,1);  /* warm up cache */
    start_counter();
    for (i = 0; i < iter; i++)
	res += absdiff(valA[i],valB[i]);
    cmeas = get_counter();
    cycles = cmeas / iter;
    return cycles;
}
Пример #8
0
static int row_all_dark( hb_title_t *title, uint8_t* luma, int row )
{
    luma += title->width * row;

    // compute the average luma value of the row
    int i, avg = 0;
    for ( i = 0; i < title->width; ++i )
    {
        avg += clampBlack( luma[i] );
    }
    avg /= title->width;
    if ( avg >= DARK )
        return 0;

    // since we're trying to detect smooth borders, only take the row if
    // all pixels are within +-16 of the average (this range is fairly coarse
    // but there's a lot of quantization noise for luma values near black
    // so anything less will fail to crop because of the noise).
    for ( i = 0; i < title->width; ++i )
    {
        if ( absdiff( avg, clampBlack( luma[i] ) ) > 16 )
            return 0;
    }
    return 1;
}
void ForegroundDetector::nextIteration(const Mat &img)
{
    if(bgImg.empty())
    {
        return;
    }

    Mat absImg = Mat(img.cols, img.rows, img.type());
    Mat threshImg = Mat(img.cols, img.rows, img.type());

    absdiff(bgImg, img, absImg);
    threshold(absImg, threshImg, fgThreshold, 255, CV_THRESH_BINARY);

    IplImage im = (IplImage)threshImg;
    CBlobResult blobs = CBlobResult(&im, NULL, 0);

    blobs.Filter(blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, minBlobSize);

    vector<Rect>* fgList = detectionResult->fgList;
    fgList->clear();

    for(int i = 0; i < blobs.GetNumBlobs(); i++)
    {
        CBlob *blob = blobs.GetBlob(i);
        CvRect rect = blob->GetBoundingBox();
        fgList->push_back(rect);
    }

}
Пример #10
0
static int column_all_dark( hb_title_t *title, uint8_t* luma, int top, int bottom,
                            int col )
{
    int stride = title->width;
    int height = title->height - top - bottom;
    luma += stride * top + col;

    // compute the average value of the column
    int i = height, avg = 0, row = 0;
    for ( ; --i >= 0; row += stride )
    {
        avg += clampBlack( luma[row] );
    }
    avg /= height;
    if ( avg >= DARK )
        return 0;

    // since we're trying to detect smooth borders, only take the column if
    // all pixels are within +-16 of the average.
    i = height, row = 0;
    for ( ; --i >= 0; row += stride )
    {
        if ( absdiff( avg, clampBlack( luma[row] ) ) > 16 )
            return 0;
    }
    return 1;
}
Пример #11
0
static int column_all_dark( hb_buffer_t* buf, int top, int bottom, int col )
{
    int stride = buf->plane[0].stride;
    int height = buf->plane[0].height - top - bottom;
    uint8_t *luma = buf->plane[0].data + stride * top + col;

    // compute the average value of the column
    int i = height, avg = 0, row = 0;
    for ( ; --i >= 0; row += stride )
    {
        avg += clampBlack( luma[row] );
    }
    avg /= height;
    if ( avg >= DARK )
        return 0;

    // since we're trying to detect smooth borders, only take the column if
    // all pixels are within +-16 of the average.
    i = height, row = 0;
    for ( ; --i >= 0; row += stride )
    {
        if ( absdiff( avg, clampBlack( luma[row] ) ) > 16 )
            return 0;
    }
    return 1;
}
/*!
 * @brief メソッドImageProcessing::getBackgroundSubstractionBinImage().背景差分によって得られた二値画像(c75)
 * @param cv::Mat& current_image, cv::Mat& background_image 
 * @return cv::Mat median_bin_image
 */
Mat ImageProcessing::getBackgroundSubstractionBinImage(Mat& current_image, Mat& background_gray_image/*, int threshold, int neighborhood, int closing_times*/)
{
	Mat current_gray_image; //!<現在のグレースケール画像(c75)
	Mat diff_gray_image; //!<背景差分画像(c74)
	Mat diff_bin_image; //!<背景差分画像の二値画像(c75)
	Mat median_bin_image; //!<背景差分画像の二値画像を平滑化したもの(c75)
	//Mat opening_image; //(仮)
	Mat closing_image;

	cvtColor(current_image, current_gray_image, CV_BGR2GRAY); //現フレームの画像をグレースケールに
	absdiff(current_gray_image, background_gray_image, diff_gray_image); //差分画像取得
	//showImage("差分画像", diff_gray_image);
	
	//EV3用
	//threshold(diff_gray_image, diff_bin_image, /*13*/20, 255, THRESH_BINARY); //二値化
	////showImage("二値画像", diff_bin_image);
	//medianBlur(diff_bin_image, median_bin_image, 7); //ノイズ除去
	////showImage("平滑化処理後", median_bin_image);
	////morphologyEx(median_bin_image, opening_image, MORPH_OPEN, Mat(), Point(-1, -1), 5); //オープニング(縮小→膨張)処理
	//morphologyEx(median_bin_image, closing_image, MORPH_CLOSE, Mat(), Point(-1, -1), 7); //クロージング(膨張→収縮)処理.穴埋めに使われる
	////showImage("穴埋め処理後", closing_image);


	threshold(diff_gray_image, diff_bin_image, th, 255, THRESH_BINARY); //二値化
	//showImage("二値画像", diff_bin_image);
	medianBlur(diff_bin_image, median_bin_image, 2*neighborhood+1); //ノイズ除去
	//showImage("平滑化処理後", median_bin_image);
	//morphologyEx(median_bin_image, opening_image, MORPH_OPEN, Mat(), Point(-1, -1), 5); //オープニング(縮小→膨張)処理
	morphologyEx(median_bin_image, closing_image, MORPH_CLOSE, Mat(), Point(-1, -1), 2*closing_times+1); //クロージング(膨張→収縮)処理.穴埋めに使われる
	//showImage("穴埋め処理後", closing_image);
	return closing_image;
	//return median_bin_image;
}
Пример #13
0
double Fractais::topDown(Mat image, int op, int p)
{
    Mat aux;
    cvtColor(image,image,CV_BGR2GRAY);
    threshold(image,image,200.0,255.0,THRESH_BINARY);
    cvtColor(image,aux,CV_GRAY2RGB);

    int r;
    switch (op) {
    case 1:
        r=image.rows-1;
        break;
    default:
        r = 0;
        break;
    }

    Vec3b cor(0,0,0);

    for(int i=0; i<aux.cols;i++){
        Vec3b c = aux.at<Vec3b>(r,i);
        if(c != cor){
            Point x(i,r);
            floodFill(aux, x, Scalar(0.0,0.0,0.0));
        }
    }

    cvtColor(aux,aux,CV_RGB2GRAY);
    absdiff(aux,image,aux);

    return press(aux,0,p);
}
Пример #14
0
bool motion(Mat& a, Mat& b) {

    Mat c;
    blur(a, a, Size(4,4));
    blur(b, b, Size(4,4));
    absdiff(a, b, c);
    Mat d(Size(320,240),CV_8UC1);
    resize(c,d,d.size());

    // Treshold
    threshold(d,d,70,255,CV_THRESH_BINARY);

    // Perform morphological close operation to filling in the gaps
    Mat kernel;
    getStructuringElement(MORPH_RECT, Size(10,10));
    morphologyEx(d, d, MORPH_CLOSE, kernel, Point(-1,-1), 5);

    // Find all contours
    vector<vector<Point> > contours;
    findContours(d.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);


    bool intruder = false;
    for (int i = 0; i < contours.size(); i++) {
        double area = contourArea(contours[i]);
        if (area > 10000 && area < 90000){
		intruder = true;
		break;
	}
    }
    return intruder;
}
Пример #15
0
usec_t AdaptiveSleep::sleepUntil(usec_t base, usec_t inc) {
	usec_t now = getusecs();
	usec_t diff = now - base;

	if (diff >= inc)
		return diff - inc;

	diff = inc - diff;

	if (diff > oversleep + oversleepVar) {
		diff -= oversleep + oversleepVar;
		usecsleep(diff);
		const usec_t ideal = now + diff;
		now = getusecs();

		{
			usec_t curOversleep = now - ideal;
			if (negate(curOversleep) < curOversleep)
				curOversleep = 0;

			oversleepVar = (oversleepVar * 15 + absdiff(curOversleep, oversleep) + 8) >> 4;
			oversleep = (oversleep * 15 + curOversleep + 8) >> 4;
		}

		noSleep = 60;
	} else if (--noSleep == 0) {
Пример #16
0
Mat computeWhiteMaskShadow(Mat& img)
 {
    // I = rgbFrame(:,:,1)>80 & rgbFrame(:,:,3)>80 | rgbFrame(:,:,3)>80 & abs(double(rgbFrame(:,:,1))-double(rgbFrame(:,:,3)))<20;
    // I = medfilt2(I,[20,20]);
	Mat BGRbands[3];  
	split(img,BGRbands);
	Mat maskB, maskG, maskR, maskD, maskT, mask;
	vector< vector<Point> > contours;
	threshold(BGRbands[0],maskB,90,255,THRESH_BINARY);
	threshold(BGRbands[1],maskG,90,255,THRESH_BINARY);
	threshold(BGRbands[2],maskR,90,255,THRESH_BINARY);
	absdiff(BGRbands[2],BGRbands[0],maskD);
	threshold(maskD,maskD,25,255,THRESH_BINARY);
	bitwise_not(maskD,maskD);
	bitwise_and(maskR,maskD,maskD);
	bitwise_and(maskB,maskR,maskT);
	bitwise_or(maskD,maskT,maskT);

	findContours(maskT, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
	vector<double> areas = computeArea(contours);
	for(int j = areas.size()-1; j>=0; j--){
		if(areas.at(j)>MAX_AREA || areas.at(j)<MIN_AREA )
			contours.erase(contours.begin()+j);
	}
	Mat out = Mat::zeros(Size(img.cols,img.rows), CV_8U);
	for (int idx = 0; idx < contours.size(); idx++)
		drawContours(out, contours, idx, Scalar(255,255,255), CV_FILLED, 8);
	return out;
 }
Пример #17
0
/*
 * input:  grayscale frame
 * output: Point2i with detected position
 */
int ObjectDetection::detectObject(Mat frame, Point2i& pixelPosition) {
  Mat diffImage, thresholdImage;
  Rect objectBounding = Rect(0, 0, 0, 0);

  // subtract background and create binary mask
  absdiff(refereceFrame, frame, diffImage); // output: grayscale
  threshold(diffImage, thresholdImage, SENSITIVITY_VALUE, 255, THRESH_BINARY); // output: binary
#ifdef SHOW_THESHOLD
  if (cam->get_cameraID() == 1) {
    imshow("cam2 threshold 1", thresholdImage);
  } else {
    imshow("cam1 threshold 1", thresholdImage);
  }
#endif

  // blur and threshold again to get rid of noise
  blur(thresholdImage, thresholdImage, cv::Size(BLUR_SIZE, BLUR_SIZE)); // output: grayscale
  threshold(thresholdImage, thresholdImage, SENSITIVITY_VALUE, 255, THRESH_BINARY); // output: binary
#ifdef SHOW_THESHOLD
  if (cam->get_cameraID() == 1) {
    imshow("cam2 threshold 2", thresholdImage);
  } else {
    imshow("cam1 threshold 2", thresholdImage);
  }
#endif

  int error = getObjectPosition(thresholdImage, pixelPosition, &objectBounding);

  if (0 == error) {
    return OK;
  } else {
    return ERR;
  }

}
Пример #18
0
void ForegroundDetector::nextIteration(const Mat &img)
{
    if(bgImg.empty())
    {
        return;
    }

    Mat absImg = Mat(img.cols, img.rows, img.type());
    Mat threshImg = Mat(img.cols, img.rows, img.type());
	std::vector<std::vector<Point> > contours;
	std::vector<std::vector<Point> > selected_contours;
	std::vector<Vec4i> hierarchy;

    absdiff(bgImg, img, absImg);
    threshold(absImg, threshImg, fgThreshold, 255, CV_THRESH_BINARY);

	findContours(absImg, contours, hierarchy,
					CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

    for(size_t i = 0; i < contours.size(); i++)
		if(contourArea(contours[i]) > minArea)
			selected_contours.push_back(contours[i]);

    vector<Rect>* fgList = detectionResult->fgList;
    fgList->clear();

    for(size_t i = 0; i < selected_contours.size(); i++)
    {
        std::vector<Point> contour = selected_contours[i];
        Rect rect = boundingRect(contour);
        fgList->push_back(rect);
    }

}
Пример #19
0
static void __stdcall
comb_mask_0_c(uint8_t* dstp, const uint8_t* srcp, const int dpitch,
              const int spitch, const int cthresh, const int width,
              const int height) noexcept
{
    const uint8_t* sc = srcp;
    const uint8_t* sb = sc + spitch;
    const uint8_t* sa = sb + spitch;
    const uint8_t* sd = sc + spitch;
    const uint8_t* se = sd + spitch;

    const int cth6 = cthresh * 6;

    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            dstp[x] = 0;
            int d1 = sc[x] - sb[x];
            int d2 = sc[x] - sd[x];
            if ((d1 > cthresh && d2 > cthresh)
                    || (d1 < -cthresh && d2 < -cthresh)) {
                int f0 = sa[x] + 4 * sc[x] + se[x];
                int f1 = 3 * (sb[x] + sd[x]);
                if (absdiff(f0, f1) > cth6) {
                    dstp[x] = 0xFF;
                }
            }
        }
        sa = sb;
        sb = sc;
        sc = sd;
        sd = se;
        se += (y < height - 3) ? spitch : -spitch;
        dstp += dpitch;
    }
}
Пример #20
0
static int row_all_dark( hb_buffer_t* buf, int row )
{
    int width = buf->plane[0].width;
    int stride = buf->plane[0].stride;
    uint8_t *luma = buf->plane[0].data + stride * row;

    // compute the average luma value of the row
    int i, avg = 0;
    for ( i = 0; i < width; ++i )
    {
        avg += clampBlack( luma[i] );
    }
    avg /= width;
    if ( avg >= DARK )
        return 0;

    // since we're trying to detect smooth borders, only take the row if
    // all pixels are within +-16 of the average (this range is fairly coarse
    // but there's a lot of quantization noise for luma values near black
    // so anything less will fail to crop because of the noise).
    for ( i = 0; i < width; ++i )
    {
        if ( absdiff( avg, clampBlack( luma[i] ) ) > 16 )
            return 0;
    }
    return 1;
}
Пример #21
0
double Fractais::leftRigth(Mat image, int op, int p)
{
    Mat aux;
    cvtColor(image,image,CV_BGR2GRAY);
    threshold(image,image,200.0,255.0,THRESH_BINARY);
    cvtColor(image,aux,CV_GRAY2RGB);

    int c;
    switch (op) {
    case 1:
        c = image.cols-1;
        break;
    default:
        c = 0;
        break;
    }

    Vec3b cor(0,0,0);
    for(int i=0; i<aux.rows;i++){
        if(aux.at<Vec3b>(i,c) != cor){
            floodFill(aux, Point(c,i), Scalar(0.0,0.0,0.0));
        }
    }

    cvtColor(aux,aux,CV_RGB2GRAY);
    absdiff(aux,image,aux);

    return press(aux,1, p);
}
Пример #22
0
static void __stdcall
motion_mask_c(uint8_t* tmpp, uint8_t* dstp, const uint8_t* srcp,
              const uint8_t* prevp, const int tpitch, const int dpitch,
              const int spitch, const int ppitch, const int mthresh,
              const int width, const int height) noexcept
{
    uint8_t* tx = tmpp;
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            tx[x] = absdiff(srcp[x], prevp[x]) > mthresh ? 0xFF : 0;
        }
        tx += tpitch;
        srcp += spitch;
        prevp += ppitch;
    }

    const uint8_t* t0 = tmpp;
    const uint8_t *t1 = tmpp;
    const uint8_t *t2 = tmpp + tpitch;

    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            dstp[x] = (t0[x] | t1[x] | t2[x]);
        }
        t0 = t1;
        t1 = t2;
        if (y < height - 2) {
            t2 += tpitch;
        }
        dstp += dpitch;
    }
}
Пример #23
0
static double maxAbsDiff(const T &t, const U &u)
{
  Mat_<double> d;
  absdiff(t, u, d);
  double ret;
  minMaxLoc(d, NULL, &ret);
  return ret;
}
Пример #24
0
Mat IPS_simple::applySubs(Mat raw_src, Mat ref_src){
    Mat dst = raw_src.clone();
    clock_t startStep = clock();
    absdiff(raw_src,ref_src,dst);
    clock_t stopStep = clock();
    double elapsedStep = (double)difftime(startStep, stopStep) * 1000.0 / CLOCKS_PER_SEC;
    printf("Tiempo de ejecucion de Substraction:\t%f\tms \n", std::abs(elapsedStep) );
    return dst;
}
Пример #25
0
static bool isClose(int32_t newSampleRate, int32_t prevSampleRate,
        int32_t filterSampleRate, int32_t outSampleRate)
{

    // different upsampling ratios do not need a filter change.
    if (filterSampleRate != 0
            && filterSampleRate < outSampleRate
            && newSampleRate < outSampleRate)
        return true;

    // check design criteria again if downsampling is detected.
    int pdiff = absdiff(newSampleRate, prevSampleRate);
    int adiff = absdiff(newSampleRate, filterSampleRate);

    // allow up to 6% relative change increments.
    // allow up to 12% absolute change increments (from filter design)
    return pdiff < prevSampleRate>>4 && adiff < filterSampleRate>>3;
}
Пример #26
0
/* repeatedly calls the function to measure until the total execution
 * time (in cycles) is above specified threshold, returns iteraction count */
int measurecnt(void)
{
    unsigned cmeas, cycles;
    int cnt = 1;
    volatile int res = 0;  /* don't let compiler optimize away fn
			      calls */
    do 
    {
	int c = cnt;
	res += absdiff(0,1);    /* first call to warm up cache */
	start_counter();
	while (c-- > 0)
	    res += absdiff(0,1);
	cmeas = get_counter();
	cycles = cmeas / cnt;
	cnt += cnt;
    } while (cmeas < CMIN);  /* make sure long enough */
    return cnt;
}
Пример #27
0
void getAbsDiffs(const Mat& rgbImg, const vector<Mat> &neighbours, vector<Mat> &absdiffs)
    {
    transform(neighbours.begin(), neighbours.end(), back_inserter(absdiffs),
        [rgbImg](const Mat& elem)
            {
            Mat res;
            absdiff(rgbImg, elem, res);
            return res;
            });
    }
Пример #28
0
	Mat meanFilter(vector<Mat> prev, Mat current) {
		Mat total = prev[0].clone();
		for (int i = 0; i < prev.size(); i++) {
			total += prev[i];
		}
		Mat diff;
		absdiff(current, total, diff);
		threshold(diff, diff, 40, 200, CV_THRESH_BINARY);
		return diff;
	}
Пример #29
0
int main(int argc, char *argv[]) {
  long x = atoi(argv[1]);
  long y = atoi(argv[2]);
  long z1 = absdiff_se(x,y);
  long z2 = gotodiff_se(x,y);
  long z3 = cmovdiff(x,y);
  long z4 = absdiff(x,y);
  long z5 = absdiff_asm(x,y);
  printf("x = %ld, y = %ld, |x-y| = (%ld,%ld,%ld,%ld,%ld)\n",
	 x, y, z1, z2, z3, z4, z5);
  return 0;
}
Пример #30
0
/**
* Subtracts two images from each other. Performs absdiff so
* order shouldn't matter. 
* @param back the background image. 
* @param fore the foreground image. 
* @return Mat the subtracted image. 
*/
Mat ImageUtils::subtractImages(Mat back, Mat fore) {
	Mat grayBack;
	Mat grayFore;
	cvtColor(back, grayBack, COLOR_BGR2GRAY);
	cvtColor(fore, grayFore, COLOR_BGR2GRAY);
	Mat sub;
	absdiff(grayBack, grayFore, sub);
	
	Mat thresh;
	threshold(sub, thresh, 120, 255, THRESH_BINARY);
	return thresh;
}