Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
fernandoc1 / extract_roi.cpp
Created September 24, 2019 21:53
This extracts a ROI from images that are 16bits per pixel.
void extractRoi(cv::Mat& inImage, cv::Mat& outImage, cv::Rect roi)
{
/* Create the image */
outImage = cv::Mat(roi.height, roi.width, inImage.type());
/* Populate the image */
for (int i = roi.y; i < (roi.y+roi.height); i++)
{
uint16_t* inP = inImage.ptr<uint16_t>(i);
uint16_t* outP = outImage.ptr<uint16_t>(i-roi.y);
@fernandoc1
fernandoc1 / timer_example.cpp
Last active September 19, 2019 19:43
This is a timer thread example with a lambda function and std::condition_variable.
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <unistd.h>
int main(int argc, char** argv)
{
std::mutex m;
@fernandoc1
fernandoc1 / test.html
Created September 12, 2019 19:45
This code tests CGI with C++ and javascript fetch function.
<html>
<body>
</body>
</html>
<script>
async function loadData()
{
let response = await fetch("http://localhost/path/to/TestCGI.bin", {
method: 'POST',
@fernandoc1
fernandoc1 / python_test.cpp
Created April 23, 2019 14:29
Access std::vector in boost::python
#include <iostream>
#include <vector>
#include <memory>
#include <boost/shared_ptr.hpp>
#include <boost/python.hpp>
#include <boost/python/stl_iterator.hpp>
#include <Python.h>
template<typename T> inline std::vector<T> pyListToStdVector(const boost::python::object& iterable)
{
@fernandoc1
fernandoc1 / Makefile
Created March 1, 2019 20:18
This code plays sound of shapes
all:
g++ morph_descriptor.cpp -o MorphDescriptor -lao -lopencv_core -lopencv_highgui -lopencv_imgproc
@fernandoc1
fernandoc1 / main.cpp
Created January 25, 2019 14:36
QProcess::finished with lambda function example.
#include <QCoreApplication>
#include <QtGlobal>
#include <QDebug>
#include "global_settings.hpp"
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
@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 / 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>
@asimshankar
asimshankar / README.md
Last active April 13, 2024 15:50
Training TensorFlow models in C

Training TensorFlow models in C

Python is the primary language in which TensorFlow models are typically developed and trained. TensorFlow does have bindings for other programming languages. These bindings have the low-level primitives that are required to build a more complete API, however, lack much of the higher-level API richness of the Python bindings, particularly for defining the model structure.

This gist demonstrates taking a model (a TensorFlow graph) created by a Python program and running the training loop in a C program.

The model

@fernandoc1
fernandoc1 / geo_helper.cpp
Created August 11, 2017 18:10
This code calculates intersection between arcs in the sphere surface and between arcs and a route.
#include "geo_helper.hpp"
#include <cmath>
//It assumes radius as 1.
QVector3D GeoHelper::QGeoCoordinate2QVector3D(QGeoCoordinate coord)
{
double radlat = qDegreesToRadians(coord.latitude());
double radlon = qDegreesToRadians(coord.longitude());