Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
fernandoc1 / db_connector.cpp
Created November 20, 2017 17:30
PostgreSQL notification with Qt5
#include "db_connector.hpp"
#include <QSqlDriver>
DBConnector::DBConnector(QString ip, int port, QString databaseName, QString username, QString password)
: db(QSqlDatabase::addDatabase("QPSQL"))
{
this->db.setHostName(ip);
this->db.setPort(port);
this->db.setDatabaseName(databaseName);
this->db.setUserName(username);
@fernandoc1
fernandoc1 / curl_http_get.cpp
Created December 6, 2017 21:44
This code is to perform http request that requires Digest authentication.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include <vector>
#include <chrono>
@fernandoc1
fernandoc1 / qt_timer_within_main.cpp
Created December 20, 2017 13:25
This code is to show how to call a function in a loop, from within the main thread in Qt.
void runCapture()
{
WebSocketCamera websocketCamera("ws://localhost/camera");
websocketCamera.start();
cv::Mat image;
int key = -1;
websocketCamera.getImage(image);
cv::imshow("DISPLAY", image);
@fernandoc1
fernandoc1 / qt_timer_within_main_with_lambda.cpp
Created December 20, 2017 17:34
C++ lambda function with Qt Timer and OpenCV example.
#include <QCoreApplication>
#include <QTimer>
#include <QDebug>
#include <memory>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char** argv)
{
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
import matplotlib.pyplot
from collections import defaultdict
@fernandoc1
fernandoc1 / Run.sh
Last active April 19, 2018 13:24
This code is used for inference in images, using the Tensorflow object detector. (https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md)
#! /bin/bash
#To run this script just type ./Run.sh <PATH TO IMAGE>
LD_LIBRARY_PATH=/home/fccoelho/Applications/anaconda3/lib/python3.6/site-packages/../../ python test_obj_detection.py $1
@fernandoc1
fernandoc1 / convert_to_tiff.cpp
Created May 4, 2018 20:50
This code is to convert raw data buffer acquired from Flir camera to a TIFF image, using libtiff
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <tiffio.h>
int main(int argc, char** argv)
{
if(argc < 2)
@fernandoc1
fernandoc1 / linear_regression.cpp
Created June 19, 2018 19:23
Linear regression from std::vector of values to be used in OpenCV.
std::pair<double, double> linearRegression(const std::vector<double>& x, const std::vector<double>& y)
{
const double n = x.size();
const double s_x = std::accumulate(x.begin(), x.end(), 0.0);
const double s_y = std::accumulate(y.begin(), y.end(), 0.0);
const double s_xx = std::inner_product(x.begin(), x.end(), x.begin(), 0.0);
const double s_xy = std::inner_product(x.begin(), x.end(), y.begin(), 0.0);
const double numer = n * s_xy - s_x * s_y; // The same regardless of inversion (both terms here are commutative)
const double denom = n * s_xx - s_x * s_x; // Will change if inverted; use this for now
double a;
@fernandoc1
fernandoc1 / image_correlation.py
Created June 25, 2018 17:58
Calculate correlation between images in python
#! /usr/bin/python
import scipy
import scipy.misc
import scipy.signal
import scipy.stats
import sys
im1 = scipy.misc.imread(sys.argv[1], mode='L')
im2 = scipy.misc.imread(sys.argv[2], mode='L')
@fernandoc1
fernandoc1 / image_correlation.py
Created June 25, 2018 20:31
Find the best image from a folder, given it's thumbnail.
#! /usr/bin/python
import os
import scipy
import scipy.misc
import scipy.signal
import scipy.stats
import sys
originalImagePath = sys.argv[1]