Skip to content

Instantly share code, notes, and snippets.

@raunaqbn
raunaqbn / Chapter_5_1
Created June 11, 2016 09:30
Chapter 5 : Problem 1
#include <iostream>
using namespace std;
/* Code to generate a LUT for parity */
short computeParity( short num )
{
short parity = 0;
while (num > 0)
{
parity ^= (x&1);
/*Bubble Sort*/
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)
// Last i elements are already in place
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
@raunaqbn
raunaqbn / gist:548339e84a5f9ea8511809fcb8b32536
Created June 14, 2016 00:34
OpenCV 2.4.13 additional lib dependencies list
opencv_calib3d2413.lib
opencv_calib3d2413d.lib
opencv_contrib2413.lib
opencv_contrib2413d.lib
opencv_core2413.lib
opencv_core2413d.lib
opencv_features2d2413.lib
opencv_features2d2413d.lib
opencv_flann2413.lib
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
#include "chapter2.h"
void display_image(char** argv, int task)
{
// Load the image passed by the user
IplImage *pImage = cvLoadImage(argv[1]);
// Create a window using the HighGUI library.
// Give the window a title and assign a name to the window for future reference.
// Setting to autosize to take the size of image. If set to zero image will be scaled to fit window
cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE );
#include "chapter2.h"
// We create global variables of the cvCapture and the trackbar position
//so that it is accessible to the callback and the main function. The callback needs
//it to handle updating the frame position in the video capture. The main function needs
//it to register the callback return count and to host the actual while loop playing the video
CvCapture* g_pCapture = NULL;
int g_sliderPostion = 0;
void handle_trackbar_callback(int position)
#include "chapter2.h"
void display_video(char **argv)
{
// CvCapture structure is used to store the information of the various properties of the
// avi and the create file capture returns a pointer of this type initialized to the beginning
// of the avi
CvCapture *pCapture = cvCreateFileCapture(argv[1]);
// Create a window to display the video frames
void mergeArrays(int * arr, int l, int m, int r)
{
// Compare element by element from arr[l:m] with arr[m:r] and accordingly move index within idividual arr
int lsize = m-l+1; // this will include the middle element
int rsize = r-m;
int L[lsize];R[rsize];
for(int i=0; i < lsize; i++)
L[i] = arr[l+i];
for(int i=0; i < rsize; i++)
R[i] = arr[m+j];
@raunaqbn
raunaqbn / quicksort.c
Last active July 16, 2016 03:36
Quick Sort
void swap(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}
void partition(int * arr, int left, int right)
{
int pivotValue = arr[right];
@raunaqbn
raunaqbn / heapsort.c
Created July 2, 2016 01:53
Heap Sort
//Heapify function is used to convert a tree rooted at node root into a max heap
void heapify (int* arr, int root, int size)
{
int pos = root;
// location of children
int left = 2*root + 1;
int right = 2*root + 2;
if (arr[root] < arr[left])