7/11/2021

Hide current working directory in terminal

 

do it on your terminal

$ export OLD_PS1=$PS1                    # save Long Prompt to OLD_PS1
$ export PS1="\u > "export PS1="\u $ "   # change to PS1 to Short Prompt
$ export PS1=$OLD_PS1                    # restore Long Prompt to PS1

7/09/2021

curlpp/cURLpp.hpp: No such file or directory

issue: 

curlpp/cURLpp.hpp: No such file or directory


solution:

install package which related with curl

> sudo apt-get install pkg-config libcurlpp-dev libcurl4-openssl-dev


* Check header file location

> dpkg -S cURLpp.hpp

libcurlpp-dev:amd64: /usr/include/curlpp/cURLpp.hpp


Thank you.


study.marearts.com

marearts



7/08/2021

C linux get Mac Address

 In my case, I failed to get Mac from eth0 devices.

So I need to check all devices to get Mac address.

This is my solution example code:

(study.marearts.com)


..

#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include <sstream>
#include <string>
#include <iostream>
std::string getMac(){
struct ifreq ifr;
struct ifconf ifc;
char buf[1024];
int success = 0;
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock == -1) { /* handle error*/ };
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) { /* handle error */ }
struct ifreq* it = ifc.ifc_req;
const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq));
int a=0;
for (; it != end; ++it) {
strcpy(ifr.ifr_name, it->ifr_name);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) {
success = 1;
break;
}
}
}
else {
/* handle error */
return "0";
}
}
unsigned char mac_address[6];
if (success)
{
memcpy(mac_address, ifr.ifr_hwaddr.sa_data, 6);
std::stringstream ss;
std::string target;
char buffer [50];
sprintf (buffer, "%x-%x-%x-%x-%x-%x", mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5]);
ss << buffer;
ss >> target;
return target;
}
return "0";
}
int main()
{
std::cout<< getMac() << std::endl;
}

..

Output is

44-a5-6e-63-a4-bb


Thank you.

marearts



python date time add or subtract

datetime package is very useful.

see the example code..

..
import datetime
print(datetime.datetime.now())
print(datetime.datetime.now().date())
lastHourDateTime = datetime.datetime.now() + datetime.timedelta(days = +10)
print(lastHourDateTime.date())
print(lastHourDateTime.time())
lastHourDateTime = datetime.datetime.now() + datetime.timedelta(hours = 10)
print(lastHourDateTime.date())
print(lastHourDateTime.time())
lastHourDateTime = datetime.datetime.now() + datetime.timedelta(hours = -10)
print(lastHourDateTime.date())
print(lastHourDateTime.time())
..
result
2021-07-08 10:19:44.969082
2021-07-08
2021-07-18
10:19:44.969146
2021-07-08
20:19:44.969164

Thank you.

study.marearts.com


7/07/2021

opencv Vector CameraParams save(yaml file store) and load(yaml file restore ) using FileNode, FileNodeIterator


Refer to load & save function.

..

std::vector<cv::detail::CameraParams> params;

bool loadCameraParams(std::string fileName){

cv::FileStorage fs(fileName+".yaml", cv::FileStorage::READ);

if(!fs.isOpened())
return false;

/////
int nObjects= 0;
fs["NC"] >> nObjects;
params.clear();
params.resize(nObjects);
/////
cv::FileNode fn = fs["cameras"];
int id=0;
for (cv::FileNodeIterator it = fn.begin(); it != fn.end(); it++,id++)
{
cv::FileNode item = *it;

cv::Mat K, R, t;
double ppx, ppy, focal, aspect;
item["K"] >> K;
item["R"] >> R;
item["t"] >> t;
item["ppx"] >> ppx;
item["ppy"] >> ppy;
item["focal"] >> focal;
item["aspect"] >> aspect;

mg_params[id].K() = (cv::Mat)K;
mg_params[id].R = R;
mg_params[id].t = t;
mg_params[id].ppx = (double)ppx;
mg_params[id].ppy = (double)ppy;
mg_params[id].focal = (double)focal;
mg_params[id].aspect = (double)aspect;
}

return true;
}

bool saveCameraParams(std::string fileName){

cv::FileStorage fs(fileName+".yaml", cv::FileStorage::WRITE);
cv::detail::CameraParams cameras = mg_params[0];
fs << "NC" << int(params.size());

fs << "cameras" << "[";
for (const auto& param : mg_params)
{
fs << "{";
fs << "K" << param.K();
fs << "R" << param.R;
fs << "t" << param.t;
fs << "ppx" << param.ppx;
fs << "ppy" << param.ppy;
fs << "focal" << param.focal;
fs << "aspect" << param.aspect;
fs << "}";
}
fs << "]";
fs.release();
return true;
}

..


Thank you!!

☕️

7/04/2021

bash: g++: command not found

 > sudo apt-get install g++




main.cpp:(.text+0x3f): undefined reference to `std::ios_base::Init::Init()'

 errors like that:

> gcc -o test main.cpp 

/usr/bin/ld: /tmp/ccoMmwaL.o: in function `__static_initialization_and_destruction_0(int, int)':

main.cpp:(.text+0x3f): undefined reference to `std::ios_base::Init::Init()'

/usr/bin/ld: main.cpp:(.text+0x54): undefined reference to `std::ios_base::Init::~Init()'

collect2: error: ld returned 1 exit status


just replace g++ instead of gcc

> g++ -o test main.cpp 


Then it would be fine!.



Thank you!


bash: objdump: command not found

> apt-get update

> apt-get upgrade

> apt-get install binutils


That's all!!


docker stop and remove all container, remove all images

 




stop all containers:
docker kill $(docker ps -q)

remove all containers
docker rm $(docker ps -a -q)

remove all docker images
docker rmi $(docker images -q)

7/03/2021

ubuntu copy all dependencies to certain folder of your executable file.

 Make copyall.sh file and make sure chmod is 775.

//

#!/bin/bash
# Author : Hemanth.HM
# Email : hemanth[dot]hm[at]gmail[dot]com
# License : GNU GPLv3
#

function useage()
{
cat << EOU
Useage: bash $0 <path to the binary> <path to copy the dependencies>
EOU
exit 1
}

#Validate the inputs
[[ $# < 2 ]] && useage

#Check if the paths are vaild
[[ ! -e $1 ]] && echo "Not a vaild input $1" && exit 1
[[ -d $2 ]] || echo "No such directory $2 creating..."&& mkdir -p "$2"

#Get the library dependencies
echo "Collecting the shared library dependencies for $1..."
deps=$(ldd $1 | awk 'BEGIN{ORS=" "}$1~/^\//{print $1}$3~/^\//{print $3}' | sed 's/,$/\n/')
echo "Copying the dependencies to $2"

#Copy the deps
for dep in $deps
do
echo "Copying $dep to $2"
cp "$dep" "$2"
done

echo "Done!"

//

And run it like this

./copy_dll.sh ./executableFileName ./copyToHere


That's all


Thank you.