Skip to content

Instantly share code, notes, and snippets.

@udaya1223
udaya1223 / mvc.c
Last active Aug 29, 2015
Write unix mv function in C
View mvc.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
int main(int ac, char *av[]){
errno = 0;
int result = 0;
@udaya1223
udaya1223 / response.c
Created Apr 9, 2014
Measure user response time using getch() funtion.
View response.c
#include <termios.h>
#include <stdio.h>
#include<time.h>
#include<stdlib.h>
static struct termios old, new;
/* Initialize new terminal i/o settings */
void initTermios(int echo)
{
@udaya1223
udaya1223 / waitforchild.c
Last active Aug 29, 2015
How to use wait() and waitpid() for handling the child processes using SIGCHLD.
View waitforchild.c
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#define DELAY 5
int counter = 0;
@udaya1223
udaya1223 / pipedemo.c
Created May 2, 2014
How to use PIPE & FORK system calls to run three commands together.
View pipedemo.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define oops(m,x) { perror(m); exit(x); }
main(int ac, char **av)
{
int thepipe[2], /* first pipe for the first and second command */
thesecondpipe[2], /* second pipe for the second and third commands*/
View openCVMatTypeCheck.cpp
string openCVType2str(int type) {
string r;
uchar depth = type & CV_MAT_DEPTH_MASK;
uchar chans = 1 + (type >> CV_CN_SHIFT);
switch ( depth ) {
case CV_8U: r = "8U"; break;
case CV_8S: r = "8S"; break;
case CV_16U: r = "16U"; break;
@udaya1223
udaya1223 / opencvmat.cpp
Last active Sep 7, 2015
How to check OpenCV Mat data type ?
View opencvmat.cpp
Mat test = Mat::zeros(nHeight, nWidth, CV_32FC4);
if(test.type() == CV_32FC4){
printf("Correct data type\n");
}
@udaya1223
udaya1223 / readingint.cpp
Created Feb 25, 2016
Reading a line of integers from command line
View readingint.cpp
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main(){
vector<int> vector_of_int;
string str;
@udaya1223
udaya1223 / rgbtohsv.cpp
Created Mar 23, 2016
Convert RGB image to HSV using OpenCV
View rgbtohsv.cpp
Mat srcImg = imread("image.jpg", CV_LOAD_IMAGE_COLOR);
Mat srcHSVImage, hue, sat, val;
vector<Mat> hsv;
cvtColor(srcImg, srcHSVImage, CV_BGR2HSV_FULL);
split(srcHSVImage,hsv);
hsv[0].copyTo (hue); //Hue channel
hsv[1].copyTo(sat); //Saturation channel
hsv[2].copyTo(val); //Value channel
@udaya1223
udaya1223 / fileName.cpp
Last active Oct 5, 2016
Formatting a file name using user input.
View fileName.cpp
#include <sstream>
#define IMAGE_FILE_PATH "../../data/WideAngle"
#define LEFT_IMAGE_FILE_PATH "../../data/WideAngle"
#define LEFT_PREFIX "left_"
#define RIGHT_PREFIX "right_"
#define IMG_NUM_PAD (4)
#define IMG_EXTENSION "bmp"
@udaya1223
udaya1223 / printOpenCVMat.cpp
Last active Dec 6, 2016
Print OpenCV single channel Mat
View printOpenCVMat.cpp
void _PrintMatrix(char *pMessage, cv::Mat &mat)
{
printf("%s\n", pMessage);
for (int r = 0; r < mat.rows; r++) {
for (int c = 0; c < mat.cols; c++) {
switch (mat.depth())
{
case CV_8U: