Skip to content

Instantly share code, notes, and snippets.

int majorityElement(vector<int>& nums) {
unordered_map<int, int> counter;
for (auto num : nums) {
if (counter.count(num))
counter[num] += 1;
else
counter[num] = 1;
}
@yiling-chen
yiling-chen / serialize-deserialize.cpp
Created January 4, 2018 03:29
Serialize and deserialize a binary search tree(BST) to make the string to transmit or store as short as possible.
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
class Codec {
public:
@yiling-chen
yiling-chen / demo.cpp
Created November 13, 2017 23:02
Usage of OpenCV C++ API to perform objection detection using MobileNet and SSD
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/utils/trace.hpp>
using namespace cv;
using namespace cv::dnn;
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This simple script generates the high/low ranked image list from the AVA dataset.
It also copies/resizes the source images to a specified folder.
This script is assumed to be placed in AVA_ROOT with a folder name 'images', which contains all the source images.
Make sure you alter the hard-coded path before using this script.
'''
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
A simple script to download the images specified in the AVA dataset from dpchallenge.
This script is assumed to be placed in AVA_ROOT which contains a folder named 'images'.
'''
import os
import urllib2
@yiling-chen
yiling-chen / gist:88f263804b4cc764b6fa
Created March 22, 2015 14:50
Convert a fisheye image to panorama view
#include <cmath>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, const char * argv[]) {
Mat img = imread("lillestromfisheye.jpg");
// assume the source image is square, and its width has even number of pixels
@yiling-chen
yiling-chen / list_image_files_in_directory.cpp
Last active December 21, 2015 06:38
List all image files (jpeg) in a specific folder.
#include <string>
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
using namespace boost::filesystem;
using std::endl;
using std::cout;
using std::cerr;
@yiling-chen
yiling-chen / integral_basics.cpp
Created August 14, 2013 03:02
Toy example of computing and manipulate integral image by OpenCV.
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char *argv[]) {
Mat m = Mat::ones(5,5, CV_8UC1);
cout << m << endl << endl;
@yiling-chen
yiling-chen / render_remote_image.cpp
Last active May 26, 2020 05:17
Use libcurl to get a remote image file and render by OpenCV.
//==================================================================================
// Description : Use libcurl to get a remote image file and render by OpenCV
// Based on the example from http://curl.haxx.se/libcurl/c/getinmemory.html
//==================================================================================
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <opencv2/opencv.hpp>