Ejemplo n.º 1
0
void ColorSeparation(const Mat targetImg, vector<StrokeCluster> &fisrtDrawCluster){
	
	// Mean shifting
	Mat colorSegment = Mat(targetImg.size(), CV_8UC3, Scalar(255, 255, 255));
	IplImage* img = cvCloneImage(&(IplImage)targetImg);
	int **ilabels = new int *[img->height];
	for (int i = 0; i < img->height; i++) ilabels[i] = new int[img->width];
	int regionNum = MeanShift(img, ilabels);
	cout << "Segment region number: " << regionNum << endl;

	vector <vector<Point>> fillRegionPoints;
	vector <Mat> fillRegions;
	vector<Scalar> colorValue;

	// Initial
	for (int i = 0; i < regionNum; i++){
		colorValue.push_back(Scalar(0, 0, 0));
		fillRegions.push_back(Mat(targetImg.size(), CV_8UC3, Scalar(255, 255, 255)));
	}
	fillRegionPoints.resize(regionNum);

	// Sort blobs size
	for (int i = 0; i < targetImg.rows; i++)
	for (int j = 0; j < targetImg.cols; j++)
	{
		int label = ilabels[i][j];
		fillRegionPoints[label].push_back(Point(i, j));
	}
	sort(fillRegionPoints.begin(), fillRegionPoints.end(), CompareLength);

	// Compute average color
	for (int i = 0; i < fillRegionPoints.size(); i++){
		int pixNum = fillRegionPoints[i].size();
		for (int j = 0; j < fillRegionPoints[i].size(); j++)
		{
			int x = fillRegionPoints[i][j].x;
			int y = fillRegionPoints[i][j].y;
			colorValue[i] += Scalar(targetImg.at<Vec3b>(x, y)[0], targetImg.at<Vec3b>(x, y)[1], targetImg.at<Vec3b>(x, y)[2])/pixNum;
		}
	}
	// Recover origin average color
	for (int i = 0; i < fillRegionPoints.size(); i++){
		Scalar color = colorValue[i];
		for (int j = 0; j < fillRegionPoints[i].size(); j++){
			int x = fillRegionPoints[i][j].x;
			int y = fillRegionPoints[i][j].y;
			colorSegment.at<Vec3b>(x, y) = Vec3b(color[0], color[1], color[2]);
			fillRegions[i].at<Vec3b>(x, y) = Vec3b(color[0], color[1], color[2]);
		}
	}

	// Background Removal
	colorValue.erase(colorValue.begin());
	fillRegions.erase(fillRegions.begin());

	ShowImg("Color Segment", colorSegment,-1);
	imwrite("Color Segment.jpg", colorSegment);
	fisrtDrawCluster.resize(fillRegions.size());
	FillSimulation(fillRegions, colorValue, fisrtDrawCluster);
}
Ejemplo n.º 2
0
opPanel::opPanel(wxWindow *parent,
                 wxWindowID id=wxID_ANY,
                 const wxPoint &pos=wxDefaultPosition,
                 const wxSize &size=wxDefaultSize
                ): wxPanel( parent, id, pos, size)
{
    m_picture[img_background] = EmbeddedImage<res_dualshock2>().Get();

    m_picture[img_start] = EmbeddedImage<res_start>().Get();
    m_picture[img_select] = EmbeddedImage<res_select>().Get();
    m_picture[img_analog] = EmbeddedImage<res_analog>().Get();

    m_picture[img_dp_left] = EmbeddedImage<res_dp_left>().Get();
    m_picture[img_dp_right] = EmbeddedImage<res_dp_right>().Get();
    m_picture[img_dp_up] = EmbeddedImage<res_dp_up>().Get();
    m_picture[img_dp_bottom] = EmbeddedImage<res_dp_bottom>().Get();

    m_picture[img_square] = EmbeddedImage<res_square>().Get();
    m_picture[img_circle] = EmbeddedImage<res_circle>().Get();
    m_picture[img_cross] = EmbeddedImage<res_cross>().Get();
    m_picture[img_triangle] = EmbeddedImage<res_triangle>().Get();

    m_picture[img_l1] = EmbeddedImage<res_l1>().Get();
    m_picture[img_l3] = EmbeddedImage<res_l3>().Get();
    m_picture[img_l2] = EmbeddedImage<res_l2>().Get();

    m_picture[img_r1] = EmbeddedImage<res_r1>().Get();
    m_picture[img_r3] = EmbeddedImage<res_r3>().Get();
    m_picture[img_r2] = EmbeddedImage<res_r2>().Get();

    m_picture[img_left_cursor] = EmbeddedImage<res_joystick_cursor>().Get();
    m_picture[img_right_cursor] = EmbeddedImage<res_joystick_cursor>().Get();

    m_picture[img_l_arrow_up] = EmbeddedImage<res_arrow_up>().Get();
    m_picture[img_l_arrow_right] = EmbeddedImage<res_arrow_right>().Get();
    m_picture[img_l_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get();
    m_picture[img_l_arrow_left] = EmbeddedImage<res_arrow_left>().Get();

    m_picture[img_r_arrow_up] = EmbeddedImage<res_arrow_up>().Get();
    m_picture[img_r_arrow_right] = EmbeddedImage<res_arrow_right>().Get();
    m_picture[img_r_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get();
    m_picture[img_r_arrow_left] = EmbeddedImage<res_arrow_left>().Get();

    for(int i=0; i<NB_IMG; ++i)
    {
        m_show_image[i] = false;
        HideImg(i);
    }
    ShowImg(img_background);
    m_show_image[img_background] = true;

    m_left_cursor_x = 0;
    m_left_cursor_y = 0;
    m_right_cursor_x = 0;
    m_right_cursor_y = 0;
}