void SegmentImage::getSegmentedImage(QVector<QImage> &segmentedQImages, QImage& contourQImage)
{
    //Returns segmented and contour images using references

    int rows = getImgRows();
    int cols = getImgCols();
    int nSeeds = getSeedNumber();

    Mat segmentationMatrix = getSegmentationMatrix();
    QVector<Mat > segmentedImages;// This will contain two segmented images: background and foreground



    //initialize both segmented images by setting background to be white
    for(int i = 0; i < nSeeds; i++)
    {
        segmentedImages.append(Mat( getImgSize(), getImgType()));
        segmentedImages[i].setTo(cv::Scalar(255, 255, 255));
    }

    //If wrong number of seeds provided, return blank images
    if(nSeeds != 2)
    {
        segmentedQImages.resize(2);
        segmentedQImages[0] = QImage(rows, cols, QImage::Format_RGB16);
        segmentedQImages[0].fill(Qt::white);
        segmentedQImages[1] = QImage(rows, cols, QImage::Format_RGB16);
        segmentedQImages[1].fill(Qt::white);
        contourQImage = QImage(rows, cols, QImage::Format_RGB16);
        contourQImage.fill(Qt::white);
        return;
    }

    for(int i = 0; i < rows; i++)
            for (int j = 0; j < cols; j++ )
            {
                // seed value #1 is 1 and #2 is 2
                // So using 1.5 as threshold we separate foreground from background
                if (segmentationMatrix.at<double>(i, j) >= 1.5)
                    segmentedImages[0].at<Vec3b>(i, j) = getIntensity(i,j);
                else
                    segmentedImages[1].at<Vec3b>(i,j) = getIntensity(i,j);
            }
    //Find contours and return the image with drawn contours
    Mat contourIm;
    //Compute the contour image
    getImageWithContour(getOrigImage(), contourIm);//contour image returned via reference

    //Save two SegmentationData images(one for background, one for foreground) into a QVector segmentedQImages
     segmentedQImages.clear();
    for(int i = 0; i < nSeeds; i++)
        segmentedQImages.push_back(cvMatToQImage(segmentedImages[i]));//convert to QImage and save in a vector

    //Convert the contour image into a QImage
    contourQImage = cvMatToQImage(contourIm);

    // All three images are returned through a reference
}
Exemple #2
0
void ilG_tex_loadimage(ilG_tex *self, struct ilA_img *img)
{
    GLenum format, internalformat, type;

    format = getImgFormat(img);
    type = getImgType(img);
    internalformat = getImgIFormat(img);
    ilG_tex_loaddata(self, GL_TEXTURE_2D, internalformat, img->width, img->height, 1, format, type, img->data);
}
Exemple #3
0
void ilG_tex_loadimage(ilG_tex *tex, struct ilA_img img)
{
    GLenum format, internalformat, type;

    format = getImgFormat(&img);
    type = getImgType(&img);
    internalformat = getImgIFormat(&img);
    ilG_tex_loaddata(tex, GL_TEXTURE_2D, internalformat,
                     img.width, img.height, 1,
                     format, type, img.data);
}
Exemple #4
0
static void tex_cube_build(ilG_tex *self, struct ilG_context *context)
{
    (void)context;
    ilA_img **faces = self->data;
    static const GLenum targets[6] = {
        GL_TEXTURE_CUBE_MAP_POSITIVE_X,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
    };

    glGenTextures(1, &self->object);
    glBindTexture(GL_TEXTURE_CUBE_MAP, self->object);
    for (unsigned i = 0; i < 6; i++) {
        glTexImage2D(targets[i], 0, getImgIFormat(faces[i]), faces[i]->width, 
                     faces[i]->height, 0, getImgFormat(faces[i]), 
                     getImgType(faces[i]), faces[i]->data);
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
Exemple #5
0
void ilG_tex_loadcube(ilG_tex *tex, struct ilA_img faces[6])
{
    static const GLenum targets[6] = {
        GL_TEXTURE_CUBE_MAP_POSITIVE_X,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
        GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
        GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
    };

    tex->target = GL_TEXTURE_CUBE_MAP;
    glGenTextures(1, &tex->object);
    glBindTexture(GL_TEXTURE_CUBE_MAP, tex->object);
    for (unsigned i = 0; i < 6; i++) {
        glTexImage2D(targets[i], 0, getImgIFormat(&faces[i]),
                     faces[i].width, faces[i].height, 0,
                     getImgFormat(&faces[i]),
                     getImgType(&faces[i]), faces[i].data);
        ilA_img_free(faces[i]);
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
int  main()
{
	int width;
	char* bayer[] = {"RG","BG","GR","GB"};
	char* controls[MAX_CONTROL] = {"Exposure", "Gain", "Gamma", "WB_R", "WB_B", "Brightness", "USB Traffic"};

	int height;
	int i;
	char c;
	bool bresult;

	int time1,time2;
	int count=0;

	char buf[128]={0};

	int CamNum=0;
	
	///long exposure, exp_min, exp_max, exp_step, exp_flag, exp_default;
	//long gain, gain_min, gain_max,gain_step, gain_flag, gain_default;

	IplImage *pRgb;


	int numDevices = getNumberOfConnectedCameras();
	if(numDevices <= 0)
	{
		printf("no camera connected, press any key to exit\n");
		getchar();
		return -1;
	}
	else
		printf("attached cameras:\n");

	for(i = 0; i < numDevices; i++)
		printf("%d %s\n",i, getCameraModel(i));

	printf("\nselect one to privew\n");
	scanf("%d", &CamNum);


	bresult = openCamera(CamNum);
	if(!bresult)
	{
		printf("OpenCamera error,are you root?,press any key to exit\n");
		getchar();
		return -1;
	}

	printf("%s information\n",getCameraModel(CamNum));
	int iMaxWidth, iMaxHeight;
	iMaxWidth = getMaxWidth();
	iMaxHeight =  getMaxHeight();
	printf("resolution:%dX%d\n", iMaxWidth, iMaxHeight);
	if(isColorCam())
		printf("Color Camera: bayer pattern:%s\n",bayer[getColorBayer()]);
	else
		printf("Mono camera\n");
	
	for( i = 0; i < MAX_CONTROL; i++)
	{
			if(isAvailable((Control_TYPE)i))
				printf("%s support:Yes\n", controls[i]);
			else
				printf("%s support:No\n", controls[i]);
	}

	printf("\nPlease input the <width height bin image_type> with one space, ie. 640 480 2 0. use max resolution if input is 0. Press ESC when video window is focused to quit capture\n");
	int bin = 1, Image_type;
	scanf("%d %d %d %d", &width, &height, &bin, &Image_type);
	if(width == 0 || height == 0)
	{
		width = iMaxWidth;
		height = iMaxHeight;
	}

	initCamera(); //this must be called before camera operation. and it only need init once
	printf("sensor temperature:%02f\n", getSensorTemp());

//	IMG_TYPE image_type;
	
	while(!setImageFormat(width, height, bin, (IMG_TYPE)Image_type))//IMG_RAW8
	{
		printf("Set format error, please check the width and height\n ASI120's data size(width*height) must be integer multiple of 1024\n");
		printf("Please input the width and height again£¬ie. 640 480\n");
		scanf("%d %d %d %d", &width, &height, &bin, &Image_type);
	}
	printf("\nset image format %d %d %d %d success, start privew, press ESC to stop \n", width, height, bin, Image_type);

	
	if(Image_type == IMG_RAW16)
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_16U, 1);
	else if(Image_type == IMG_RGB24)
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 3);
	else
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 1);

	setValue(CONTROL_EXPOSURE, 100*1000, false); //ms//auto
	setValue(CONTROL_GAIN,getMin(CONTROL_GAIN), false); 
	setValue(CONTROL_BANDWIDTHOVERLOAD, getMin(CONTROL_BANDWIDTHOVERLOAD), false); //low transfer speed

	setValue(CONTROL_WB_B, 90, false);
 	setValue(CONTROL_WB_R, 48, false);
  	setAutoPara(getMax(CONTROL_GAIN)/2,10,150); //max auto gain and exposure and target brightness
//	EnableDarkSubtract("dark.bmp"); //dark subtract will be disabled when exposure set auto and exposure below 500ms
	startCapture(); //start privew


	

	bDisplay = 1;
#ifdef _LIN
	pthread_t thread_display;
	pthread_create(&thread_display, NULL, Display, (void*)pRgb);
#elif defined _WINDOWS
	HANDLE thread_setgainexp;
	thread_setgainexp = (HANDLE)_beginthread(Display,  NULL, (void*)pRgb);
#endif

	time1 = GetTickCount();
	int iStrLen = 0, iTextX = 40, iTextY = 60;
	void* retval;
//	int time0, iWaitMs = -1;
//	bool bGetImg;
	while(bMain)
	{

//		time0 = GetTickCount();
		getImageData((unsigned char*)pRgb->imageData, pRgb->imageSize, 200);

//		bGetImg = getImageData((unsigned char*)pRgb->imageData, pRgb->imageSize, iWaitMs);
		time2 = GetTickCount();
//		printf("waitMs%d, deltaMs%d, %d\n", iWaitMs, time2 - time0, bGetImg);
		count++;
		
		if(time2-time1 > 1000 )
		{
			sprintf(buf, "fps:%d dropped frames:%lu ImageType:%d",count, getDroppedFrames(), (int)getImgType());

			count = 0;
			time1=GetTickCount();	
			printf(buf);
			printf("\n");

		}
		if(Image_type != IMG_RGB24 && Image_type != IMG_RAW16)
		{
			iStrLen = strlen(buf);
			CvRect rect = cvRect(iTextX, iTextY - 15, iStrLen* 11, 20);
			cvSetImageROI(pRgb , rect);
			cvSet(pRgb, CV_RGB(180, 180, 180)); 
			cvResetImageROI(pRgb);
		}
		cvText(pRgb, buf, iTextX,iTextY );

		if(bChangeFormat)
		{
			bChangeFormat = 0;
			bDisplay = false;
			pthread_join(thread_display, &retval);
			cvReleaseImage(&pRgb);
			stopCapture();
			
			switch(change)
			{
				 case change_imagetype:
					Image_type++;
					if(Image_type > 3)
						Image_type = 0;
					
					break;
				case change_bin:
					if(bin == 1)
					{
						bin = 2;
						width/=2;
						height/=2;
					}
					else 
					{
						bin = 1;
						width*=2;
						height*=2;
					}
					break;
				case change_size_smaller:
					if(width > 320 && height > 240)
					{
						width/= 2;
						height/= 2;
					}
					break;
				
				case change_size_bigger:
				
					if(width*2*bin <= iMaxWidth && height*2*bin <= iMaxHeight)
					{
						width*= 2;
						height*= 2;
					}
					break;
			}
			setImageFormat(width, height, bin, (IMG_TYPE)Image_type);
			if(Image_type == IMG_RAW16)
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_16U, 1);
			else if(Image_type == IMG_RGB24)
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 3);
			else
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 1);
			bDisplay = 1;
			pthread_create(&thread_display, NULL, Display, (void*)pRgb);
			startCapture(); //start privew
		}
	}
END:
	
	if(bDisplay)
	{
		bDisplay = 0;
#ifdef _LIN
   		pthread_join(thread_display, &retval);
#elif defined _WINDOWS
		Sleep(50);
#endif
	}
	
	stopCapture();
	closeCamera();
	cvReleaseImage(&pRgb);
	printf("main function over\n");
	return 1;
}