Blog Image


About the blog

In this blog I will keep track of projects I develop though out this year and may be in the future. For now it is juts a testing ground for developing the blog itself but I hope as I put more material it will become a good place for me to hold information.

quick gstream address

Uncategorised Posted on 21 Jul, 2020 09:28:24

gst-launch-1.0 -e rtspsrc location=rtsp:// latency=0 buffer-mode=auto ! decodebin ! x264enc ! mp4mux ! filesink location=test1.mp4

gst-launch-1.0 -e rtspsrc location=rtsp:// latency=0 buffer-mode=auto ! decodebin ! videoconvert ! xvimagesink sync=false

Salmon Sizing

Fish Farming Posted on 19 Jun, 2020 08:19:00

Fish Weight Calculations

The fish weights are calculated with the formulas below. If a fish girth is not specified, the default value Fish Girth = 0.58 × Length is used.

Trout, steelhead, mackerel, snook, redfish, bonefish

Fish Weight = Length × Girth × Girth / 900

Salmon, bass

Fish Weight = Length × Girth × Girth / 800


Fish Weight = Length × Length × Length / 3500

Pike, gar

Fish Weight = Length × Length × Length / 2700

Sunfish, bluegill

Fish Weight = Length × Girth × Girth / 1200


Win32 C++ Folder dialog

Uncategorised Posted on 17 Jun, 2020 14:21:44
    BROWSEINFO   bi; 
    ZeroMemory(&bi,   sizeof(bi)); 
    TCHAR   szDisplayName[MAX_PATH]; 
    szDisplayName[0]    =   '';  

    bi.hwndOwner        =   NULL; 
    bi.pidlRoot         =   NULL; 
    bi.pszDisplayName   =   szDisplayName; 
    bi.lpszTitle        =   _T("Please select a folder for storing received files :"); 
    bi.ulFlags          =   BIF_RETURNONLYFSDIRS;
    bi.lParam           =   NULL; 
    bi.iImage           =   0;  

    LPITEMIDLIST   pidl   =   SHBrowseForFolder(&bi);
    TCHAR   szPathName[MAX_PATH]; 
    if   (NULL   !=   pidl)
         BOOL bRet = SHGetPathFromIDList(pidl,szPathName);
         if(FALSE == bRet)

Simple Server Socket C++

C/C++ Programming, Linux Posted on 01 Jun, 2020 12:01:41

This is a simple sever written in C++ and the original code can be found in “The definitive guide to Linux network programming” book.

#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>

const char APRESSMESSAGE[] = "APRESS - For Professionals, by Professionals!\n";

int main(int argc, char *argv[])
	int simpleSocket = 0;
	int simplePort = 0;
	int returnStatus = 0;
	struct sockaddr_in simpleServer;
	// make sure we va a port number
	if (argc != 2){
		fprintf(stderr, "Usage: %s <port>\n", argv[0]);
	// Create streaming socket
	simpleSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (simpleSocket == -1){
		fprintf(stderr, "Could not create a socket!\n");
	else {
		fprintf(stderr, "Socket created!\n");
	// retrieve the port number for listing
	simplePort = atoi(argv[1]);
	// Set up address strucuter
	std::memset(&simpleServer, '\0',sizeof(simpleServer));
	simpleServer.sin_family = AF_INET;
	simpleServer.sin_addr.s_addr = htonl(INADDR_ANY);
	simpleServer.sin_port = htons(simplePort);
	returnStatus = bind(simpleSocket, (struct sockaddr*)&simpleServer, sizeof(simpleServer));
	if (returnStatus == 0){
		fprintf(stderr, "Bind Completed!\n");
	else {
		fprintf(stderr, "Could not bid the address!\n");
	// Listen on the socket for connection
	returnStatus = listen(simpleSocket, 5);
	if (returnStatus == -1){
		fprintf(stderr, "Cannot listen to socket\n!");
	while(1) {
		struct sockaddr_in clientName = { 0};
		int simpleChildSocket = 0;
		socklen_t clientNameLength = sizeof(clientName);
		simpleChildSocket = accept(simpleSocket, (struct sockaddr *)&clientName, &clientNameLength);
		if (simpleChildSocket == -1){
			fprintf(stderr, "Cannot accept connections!\n");
		write(simpleChildSocket, APRESSMESSAGE, strlen(APRESSMESSAGE));
	return 0;


C/C++ Programming Posted on 04 Mar, 2020 10:23:27

Use DYNAMIC_DOWNCAST to get ribbon objects

Projecting point to world coordinate

OpenCV & C++ Posted on 19 Nov, 2019 13:48:42

This post is a copy of an original answer from the OpenCV forum, I copied here so I can have fast access from my webpage and for future archiving just in case. Original post can be found at:

You need to obtain the tvecrvec and rotationMatrix. The first two you get them through the solvePnP() function and the latter through the Rodrigues() function. Once you have this information in addition to the camera calibration coefficients you can transform the pixel point to world coordinates point. The code should be something like that (it is taken from an old project of mine):

cv::Mat intrinsics, distCoeffs;
cv::Mat rotationMatrix, rvec, tvec;

// WorldPlane are the 3D coordinate of the pattern used to solvePnP
// ImagePlane points are from pattern detection e.g: cv::findChessboardCorners
cv::solvePnP(worldPlane, imagePlane, intrinsics, distCoeffs, rvec, tvec);

cv::Mat uvPoint = cv::Mat::ones(3,1,cv::DataType<double>::type); //u,v,1

// image point to project<double>(0,0) = 3.; //got this point using mouse callback<double>(1,0) = 134.;

cv::Mat tempMat, tempMat2;
double s, zConst = 0;
tempMat = rotationMatrix.inv() * intrinsics.inv() * uvPoint;
tempMat2 = rotationMatrix.inv() * tvec;
s = zConst +<double>(2,0);
s /=<double>(2,0);
cv::Mat wcPoint = rotationMatrix.inv() * (s * intrinsics.inv() * uvPoint - tvec);

cv::Point3f realPoint(<double>(0, 0),<double>(1, 0),<double>(2, 0)); // point in world coordinates


Comments as per forum post

So you basically invert the pinhole camera equation and find out s such that the ray intersects with the z = 0 plane?


Thanks for your complete answer. Is it possible that instead of using solvepnp I fill rvec and tvec? Based on IMU data?

I have the rotation [Roll, Pitch, Yaw] and transition from the Z=0 plane which is [X, Y, Z].

If it is possible could you briefly tell me how can i fill rvec and tvec?


@above something like that. @Top I do not know/remember that, the project that I worked with it was 2 years ago, and since then there was not need to work with it again so some of the information/knowledge faded out. But try to search with the keywords that I gave you at the comment in your opening question. I still remember that there was a lot of material, with examples as well, to read about it when I was searching at that point.


What is these worldPlaneimagePlane two parameters for? And how to determine?



I did this, and also this related article on StackOverflow:…

with that same image (its the image described there), and I can’t get the positions (realPoints) right!

And of course, when I proyected them back, they are well off.

Also, in :

s = zConst +<double>(2,0);

s /=<double>(2,0);

The “2” is because is z-constant? its the z-pos in the matrix? being z the vertical axis, zeroed at floor?

OpenCV Aruco Marker Creator

C/C++ Programming Posted on 15 Nov, 2019 16:25:24

This is a link to generate Aruco markers controlling the size of the market in mm

Simplest Color Balance

C/C++ Programming Posted on 14 Aug, 2019 17:11:06
void SimplestColorBalance(cv::Mat inArray, cv::Mat &outArray, int percent)
    if (percent<= 0)
    percent = 5;

    inArray.convertTo(inArray, CV_32F);
    int rows = inArray.rows;
    int cols = inArray.cols;
    int chnls = inArray.channels();
    double halfPercent = percent /200.0;
    std::vector<cv::Mat> channels;
    std::vector<cv::Mat> results;
    if (chnls == 3){
        cv::split(inArray, channels);
    else {

    for (int i = 0; i < chnls; i++){
        cv::Mat flat;
        cv::sort(flat, flat, cv::SORT_ASCENDING);
        double lowVal =<float>(0, floor(flat.cols * halfPercent));
        double topVal =<float>(0, ceil(flat.cols * (1.0-halfPercent)));
        cv::Mat channel = channels[i];
        for (int m = 0; m < rows; m++){
            for (int n = 0; n < cols; n++){
                if (<float>(m, n) < lowVal)
          <float>(m, n) = lowVal;
                if (<float>(m, n) > topVal)
          <float>(m, n) = topVal;
        cv::normalize(channel, channel, 0, 255, cv::NORM_MINMAX);
        //channel.convertTo(channel, CV_32F);
    cv::merge(results, outArray);
    outArray.convertTo(outArray, CV_8U);

« PreviousNext »