Archiv nach Monaten: April 2012

OpenCV :: Kinect VideoCapture data in IplImage

To use functions in OpenCV like cvSmooth or cvAdaptiveThreshold you must have the data of your VideoCapture in an IplImage object.

VideoCapture capture;
Mat grayImage;
IplImage *imgSrc, *imgResult;

imgSrc = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
imgResult = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);

capture.open(CV_CAP_OPENNI);
if (!capture.isOpened()) {
	cout << "Can not open a capture object." << endl;
	return -1;
}
capture.set(CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, CV_CAP_OPENNI_VGA_30HZ);

for(;;) {
	if (!capture.grab()) {
		cout << "Can not grab images." << endl;
		return -1;
	}
	else {
		if (capture.retrieve(grayImage, CV_CAP_OPENNI_GRAY_IMAGE)) {
			imgSrc->imageData = (char *) grayImage.data;
			cvShowImage("Source", imgSrc);

			cvSmooth(imgSrc, imgResult, CV_BLUR, 100, 100);
			cvShowImage("Result", imgResult);
		}
	}
	if (waitKey(30) >= 0)
		break;
}
VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

OpenCV :: Convert Mat into IplImage

I’ve search long time for having result on this problem. I want to use the object of IplImage, which data should be filled from Mat. If you using the simple solution found on stackoverflow, then you can’t access the methods of the IplImage object.

Mat matImage;
IplImage iplImage;

iplImage = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 1);
iplImage->imageData = (char *) matImage.data;
VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Android :: create dynamic table programmatically

My problem was to create a dynamic table and not hard xml-coded. So I’ve wrote a table class to create it programmatically. The created table has also borders.

TableGenerator class

public class TableGenerator {
    private final Context mContext;
    private TableLayout mTable;

    private TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams();
    private TableRow.LayoutParams colParams = new TableRow.LayoutParams();

    public TableGenerator(Context context) {
        mContext = context;
        mTable = new TableLayout(context);
        rowParams.setMargins(0, 0, 0, 1);
        colParams.setMargins(0, 0, 1, 0);

        TableLayout.LayoutParams lptable = new TableLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        mTable.setLayoutParams(lptable);

        mTable.setStretchAllColumns(true);
        mTable.setBackgroundColor(mContext.getResources().getColor(
                R.color.table_background));
    }

    public void addRow(String[] data) {
        TableRow tr = new TableRow(mContext);
        tr.setBackgroundColor(mContext.getResources().getColor(
                R.color.table_background));

        tr.setLayoutParams(rowParams);

        for (int iCol = 0; iCol < data.length; iCol++) {
            TextView tvCol = new TextView(mContext);
            tvCol.setText(data[iCol]);
            tvCol.setGravity(Gravity.CENTER | Gravity.CENTER);
            tvCol.setPadding(3, 3, 3, 3);
            tvCol.setTextColor(mContext.getResources().getColor(
                    R.color.text_black));
            tvCol.setLayoutParams(colParams);
            tvCol.setBackgroundColor(mContext.getResources().getColor(
                R.color.row_background));
            tr.addView(tvCol);
        }

        mTable.addView(tr);
    }

    public TableLayout getTable() {
        return mTable;
    }
}

how to use the class:

MainActivity class

public class MainActivity extends Activity {
	private ScrollView layMain;
	private TableGenerator mTable;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_main);

		showTable();
	}

	private void showTable() {
		mTable = new TableGenerator(getApplicationContext());
		layMain = (ScrollView)findViewById(R.id.table);

		String[] firstRow = {"col1", "col2", "col3", "col4"};
		String[] secondRow = {"11", "12", "13", "14"};
		String[] thridRow = {"2a", "2b", "2c", "2d"};

		mTable.addRow(firstRow);
		mTable.addRow(secondRow);
		mTable.addRow(thridRow);

		layMain.removeAllViews();
		layMain.addView(mTable.getTable());
	}
}

to successfully use the code above you need to set the main.xml in layout folder to

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/table"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ScrollView>

</LinearLayout>

now we need some color and string definitions res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<string name="app_name">Table</string>
	<color name="table_background">#999999</color>
	<color name="row_background">#ffffff</color>
</resources>

Downloads

Table.zip (Project files)
Table-180x300 in Android :: create dynamic table programmatically

VN:F [1.9.22_1171]
Rating: 4.8/5 (4 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 2 votes)