Wednesday, August 21, 2019

IP address, MTU setting on Linux for FLIR Point Grey GigE cameras

It looks like my hardware does not support jumbo frames - https://linuxconfig.org/how-to-enable-jumbo-frames-in-linux

Even after setting up a larger MTU with ifconfig,
https://www.flir.com/support-center/iis/machine-vision/knowledge-base/lost-ethernet-data-packets-on-linux-systems/
the MTU reverted back to 1500. So, probably hardware or driver limited.

Also, Network Manager then complains that the interface is not managed,
https://askubuntu.com/questions/71159/network-manager-says-device-not-managed

But the camera works as long as the IP address is set correctly. According to the knowledge base article at
https://www.flir.in/support-center/iis/machine-vision/knowledge-base/setting-an-ip-address-for-a-gige-camera-to-be-recognized-in-linux/

setting it anywhere in the 169.254.x.y range with a 255.255.0.0 netmask should do the trick - link local address (LLA).

More info about our camera is at
https://www.flir.com/products/blackfly-s-gige/?model=BFS-PGE-16S2M-CS

https://www.flir.com/support-center/iis/machine-vision/knowledge-base/technical-documentation-bfs-gige/

Getting Started Manual which talks about Windows installation
Technical Reference which gives frame rates, pin-outs etc

Edit - found this page which has a good explanation of the bandwidth used, effect of lower MTU (slightly higher CPU usage), multiple GigE cameras and so on.

Sunday, August 18, 2019

Remmina, RDP and sound

For convenience, I was trying out using Sound Forge and other audio editing software on my laptop, after logging in with a Remote Desktop Connection using Remmina as the client. With the default setting, Sound Forge etc would complain that there is no suitable audio output device. Googling, found that RDP has various options - taking sound to remote client, leaving the sound on local machine, or no sound at all. Remmina default was no sound. Tried bringing sound to local device, but that did not work for DirectSound, since I'm on Linux Mint. Changing it to leave at local, SF etc would work properly.

image.png

tried ubuntu install from mint

 https://help.ubuntu.com/lts/installation-guide/i386/apds04.html

but apt update after chroot seemed to be taking the values from sylvia.

So, simpler to just use a bootable usb to create and install the new ubuntu partition.

Wednesday, August 14, 2019

moving mailing list to google groups

The process begun in Dec 2017 was completed now, in mid-Aug. Transitioning our mailing list with 60k subscribers to google groups. Had to move slowly due to the limits set on directly adding users, 100 per day per group, and only in batches of 10 email ids per addition.

Had asked PB to unconfirm users who have been moved to groups instead of unsubscribe, because unsubscribe will send them a mail saying they have been unsubscribed.

Points to note: 
(a) any user you add will get an email
(b) for a strictly mailing list only functionality, remove posting permissions for everyone except owner and manager, under Permissions -> Posting Permissions, like
Inline image 1

Google groups does handle bounces, and it is advisable to remove ids which bounce -
https://productforums.google.com/forum/#!msg/apps/5PCc-uDVowo/S4A4YPnnzXcJ

(Automating signup though google docs or google forms or something would be great. An example is given here,
https://sites.google.com/site/sandorexampleclub/how-to/step-11
  PS wrote his own implementation which is on script.google.com as a GSuite script, I think.)

Tuesday, August 13, 2019

easy 3D volumetric rendering with imagej

ImageJ, or its full-featured version Fiji, makes it easy to create volumetric renderings and flythroughs using the 3D Viewer plugin. Plugins are installed by just copying the jar file into the plugins folder, found using locate on my system at ~/.imagej/plugins. Multi-layer tifs or gifs can be used as input. Gimp cannot create multilayer tifs, but it can create gif animations, which are sufficient. Open as layers in Gimp to select multiple layer files, save as animated gif, open in ImageJ.

Inside ImageJ, Image -> Scale allows setting of proper scale. Making one axis longer etc. The Image menu also has Crop, Duplicate, Transform and Zoom. Image -> Adjust has Threshold, Brightness/Contrast, etc. Then, Plugins -> 3D Viewer.

The 3D Viewer plugin has nice recording features, with a built-in 'Record 360 degree rotation' under its View menu. It opens another Movie window, which can then be exported using ImageJ's File -> Save as and choosing Gif.

ezgif.com helps to crop and compress gifs easily.



Monday, August 12, 2019

creating animated gif or video from Octave

My Octave install does not have the campos function, but the latest version seems to have it. So, this could be useful in the future.

This post has some good guidelines - using
set(0, 'defaultfigurevisible', 'off');
to speed up things, and using print to save as png. Then using mencoder etc to create the movie.
 mencoder mf://output/*.png -mf w=640:h=480:fps=25:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

Sunday, August 11, 2019

bulk renaming from commandline on linux

Using the rename tool,
An example is
rename 's/\.html$/\.php/' *.html
From
we see that a normal string substitution would be like
s/dog/cat/

rename -n 's/SV_2019_08_10_PM_SOME_LONG_NAME/SV_2019_08_10_SHORTNAME/' SV*mp3
shows what it will do, and -v will actually do it and also display the result.

Tuesday, July 16, 2019

using DMCTK with CMake on Linux

This stackoverflow post mentions an old version of CMake and making on Windows. More googling led to FindDCMTK on cmake.org  so that I could just edit my CMakelists.txt to read

...snip...
find_package(USB-1 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(DCMTK REQUIRED)

include_directories($(USB_1_INCLUDE_DIR))
include_directories($(OpenCV_INCLUDE_DIR))
include_directories($(DCMTK_INCLUDE_DIRS))

... snip ...
target_link_libraries(${FILENAME1} ${LIBUSB_1_LIBRARIES} ${OpenCV_LIBS} ${DCMTK_LIBRARIES} )
 ... snip ...

That worked nicely, without having to manually find the libraries and so on.

Tuesday, July 02, 2019

mounting a windows smb share and automating file moves

mounted //PATH/FOLDER on a linux machine onto a folder /path/to/mountdir using

sudo mount -t cifs //192.168.ip.address/FOLDER path/to/mountdir -o uid=usernameofowner,username=username,password=xxxxx

A cron job was added to automatically move files every 5 minutes, like
*/5 * * * * mv /path/to/mountdir/LIVE_*  /path/to/another/dir/

But that caused problems, generating hundreds of emails to usernameofowner, saying mv: cannot stat ‘/path/to/mountdir/LIVE_*’: No such file or directory whenever there was no file there to move. So, PB modified the cron by adding
> /dev/null 2>&1 
which seems to have solved the issue, working well.

Wednesday, June 12, 2019

income tax filing quirks for assessment year 2019-20

This year, I thought of filing ITR1, since I only had short-term capital losses and no gains. But on downloading the pre-filled XML and trying to pre-fill the java utility, it gave an error that the xml is not valid. Then tried ITR2 java utility, with ITR2 prefilled XML. This time it mentioned that the assessment year is wrong. Manually edited 2018 to 2019 in the XML, and it pre-filled successfully.

ITR2 needed Basic Salary and DA. So, I computed it from my salary slips, as a percentage of gross salary.

Unfortunately, the CG (Capital Gains) section was not working properly in the java utility (AY2019-20 version 1.2). The Mutual Fund section's form was not being displayed, only the instructions were being displayed. So, I did not put in my losses to carry forward to the next year.

The tax computation is in the tab Part B TTI. When you click on Save, it does validation. This time, there was also a Submit button, which allows you to directly submit the return from the java utility itself. I did that, and the ITR-V was sent to my email. I chose to e-verify via HDFC bank's netbanking like in this earlier post. The first time I tried, I was logged on to the incometax portal when I started the process, so it did not work. I needed to log out of the incometax portal, and then click on the Income tax e-filing link under Requests in HDFC bank's netbanking. Then it worked. 

Wednesday, May 29, 2019

ffmpeg commandline for maximum compatibility

An old Raspberry Pi was not playing some videos. Looked around for a transcoding option with ffmpeg, baseline x264 seemed fine, and this example worked for me -
ffmpeg -i input.avi -c:v libx264 -preset slow -crf 22 -c:a copy -profile:v baseline -level 3.0 output.mp4
by looking at

Another post has the 2-pass encoding example, where the bitrate is also specified. 

Tuesday, May 21, 2019

videos for waiting area - redux

The original idea of having a marquee which would update as in my previous post turned out to be not very workable. Even if the wifi was not flaky, updating the times etc on a computer in the office would be "too much work" for us in the middle of shows. And the wifi signal was being completely lost due to electrical noise from our solar system exhibit's motor and my room's AC compressor motor. So, the idea was adapted to showing a notice in 3 languages, that the average wait time is 30 minutes, every five minutes or so.

Notice made in Google docs and screenshotted, added an "invert" filter scrolling up-down for visibility.

The next change was to use the "smart TV" media playback for the two flat screens instead of buying Raspberry Pis for them. Since anyway the content was going to be static, did not make sense to buy. Idea suggested by S.

The "smart" TVs would only play a single video file, would need intervention after a single video file was played, would not play playlists. So, strung together all the files into a single file, repeated it for 3 hours so that no intervention would be needed. I had used avidemux, vdub, ffmpeg for doing this, but S more comfortable with VSDC on Windows.

Ffmpeg commandline for making files of known size - first calculate required bitrate by size / duration, using kbits and seconds, then something like
for half an hour 500 MB, = 500 * 1000 * 8 kbits
bitrate = file size / duration
=4000000/1800 = 2222 kbps. Let's take as 2200 kbps.
so, 2200k

ffmpeg -y -i input -c:v libx264 -preset medium -b:v 2200k -pass 1 -c:a libmp3lame -b:a 128k -f mp4 /dev/null && \ 
ffmpeg -i input -c:v libx264 -preset medium -b:v 2200k -pass 2 -c:a libmp3lame -b:a 128k output.mp4

In the ffmpeg example obtained by googling, it was AAC audio. But on my machine,
 Unknown encoder 'libfdk_aac'
So, used libmp3lame instead.

Playing the single file on the Pis had some issues. The older Pi would not play, since it did not support the codec -  x264 High Profile, I think. The other Pi had vignetting issues, the 16x9 videos were appearing too small on the 4x3 TVs. So, the Pis play playlists, and the "smart" TVs play single video files. The older Pi does not play VP8. Files downloaded from Youtube via desktop (MPEG4 codec) were fine, downloaded via mobile by S were VP8.

Also learned that the Raspberry Pi overscan controls do not work with VLC in fullscreen mode (on RPi3).

Also learned that the Raspberry Pi (2 and 3) video out pinout of the TRRS connector did not have Sleeve as ground! TRRS = L, R, GND, Video! Had to modify the TRRS to RCA cable we bought, inverting GND and VID for one of the RCAs.

For getting composite video out, 0 is NTSC and 2 is PAL,
https://www.raspberrypi.org/documentation/configuration/config-txt/video.md

if only sdtv_out=2 does not work,

https://bhavyanshu.me/tutorials/force-raspberry-pi-output-to-composite-video-instead-of-hdmi/03/03/2014/

And with the remote for shutting down the Pis, they can be operated completely independent of wifi availability.

Sunday, May 12, 2019

Veracrypt fix

A Veracrypt volume on a removable (NTFS) hard disk was not mounting. Veracrypt was complaining of bad password or bad volume. I thought the password was correct. Finally, did
sudo fdisk -l
to find the device name, which was /dev/sdc1 for the removable drive in this case, and then
sudo ntfsfix /dev/sdc1
It finished in less than a second, noting that it had successfully completed. Then, tried mounting with Veracrypt, success!

After mounting, the encrypted volume was visible in Nemo with an icon to unmount it. But unmounting it with Nemo does not really unmount it, probably because Veracrypt uses su privileges to mount - you have to unmount (or Dismount) it via the Veracrypt interface. Only then would the removable drive become free of processes and unmountable via Nemo.



Thursday, May 02, 2019

Octave memory issues and workaround

I had an Octave script which was reading data from files into a variable, doing some processing, then reading some different data into the same variable, and so on. For many hundreds of MB of data, using the load function. But Octave was running out of memory, and finally I had to
killall -9 octave-gui

The workaround was to process part of the data, save the intermediate data to file, exit Octave, reload Octave, resume processing, and so on. Painful, but it worked. 

Wednesday, April 24, 2019

chapterwise references with LaTEX and biblatex

I needed chapterwise references for my thesis. The suggestions at
https://tex.stackexchange.com/questions/345163/references-at-the-end-of-each-chapter
did not work with the "Cambridge" template on Overleaf.

or use TU Delft template which has per chapter references.


used that, and found:

The chapterbib package and biblatex are incompatible

Then got this - 

That seemed to work - \begin refsection etc 

% Chapter 1
\begin{refsection}
\chapter{Introduction} % Main chapter title

---snip----

% and at the end, where we want the references

\renewcommand{\bibname}{References}
% 20190501 - HN
% added this renewcommand to change  the title Bibliography to References
\printbibliography
\end{refsection}

Tuesday, April 16, 2019

mailstore for achiving emails

Here is part of an email to a colleague regarding Google Apps email reaching storage limits:

Regarding email - currently, our domain does not allow expansion of the existing amount of space. So, the only way is to delete large attachments. In many cases, the attachments are required and cannot be deleted. This can be handled in many ways.

1. Forward them themewise to specially created gmail ids and then delete
2. archive them locally by storing on a local hard disk and then delete
3. automate the local archiving using some tool like
https://www.google.com/search?q=imap+archive+tool+open+source

I guess you would want to work on Windows? I have not tried any of these tools, but this free Windows tool comes near the top in search results -
https://www.mailstore.com/en/products/mailstore-home/

And later, when he tried out mailstore, found that it had a specific option to get authorized for GMail - using that option, downloading emails was quite painless, though a long process for many GB of emails.

Thursday, April 11, 2019

voting in India

Today is polling day for us. Both State and National elections being held simultaneously here. Though the printed slips with our electoral roll serial number and polling booth location were given to us from our workplace, it is also available for all as an app,
https://play.google.com/store/apps/details?id=com.eci.citizen&hl=en_IN

Lots of information is available online as well as on the app, for example, the eligibility criteria and how to register,
https://eci.gov.in/faqs/

My experience was relatively seamless. Waited for around 20 minutes in line - around 20 people in line in front of me, including elderly ladies who had to be prompted on how to use the machine etc. All done in a harmonious manner. Very civilized. A demo video is at
https://eci.gov.in/video-gallery/evm-awareness/know-your-evm-r61/

Friday, April 05, 2019

Raspberry Pi shutdown using IR remote

Initially followed this instructable -

Had to make changes because of new version of Raspbian and lirc.

1. Added sensor as per this,
changing pinout as required by googling
2. Installation by
sudo apt-get update
sudo apt-get install lirc



3. Configuring kernel module was different from
The only thing we need to do is to uncomment out
dtoverlay=lirc-rpi
in /boot/config.txt

4. Configuration was slightly different from
(a) create /etc/lirc/hardware.conf and put in it
LOAD_MODULES=true
DRIVER="devinput"
DEVICE="/dev/lirc0"
(b) Placing the remote's configuration file was inside the directory /etc/lirc/lircd.conf.d
(c) starting the service was by /etc/init.d/lircd start

5. irexec configuration was different from
We needed to edit /etc/lirc/irexec.lircrc instead, since we want to shutdown and reboot, editing it to:
begin
    prog   = irexec
    button = KEY_1
    config = sudo shutdown -r now
end
begin
    prog   = irexec
    button = KEY_0
    config = sudo shutdown -h now
end


6. irrecord was a little tricky -
(Here also, instead of service lircd stop, we need to do /etc/init.d/lircd stop)

irrecord first wants you to press random keys. Then, you have to give the name of a key, press and hold it, then enter the next key's name when prompted, and so on for all the keys, and then only press ENTER to stop the process. And some keys are not recognized - maybe those should have been pressed during the first phase of random pressing.

7.  sudo /etc/init.d/lircd status reports error with duplicate remotes. We need to rename /etc/lircd/lircd.conf.d/devinput.lircd.conf to devinput.lircd.conf.dist
sudo mv devinput.lircd.conf devinput.lircd.conf.dist

8. sudo /etc/init.d/lircd status reports errors like
lircd-0.9.4c[364]: Error: Cannot glob /sys/class/rc/rc0/input[0-9]*/event[0-9]*
Then we need to edit /etc/lirc/lirc_options.conf, changing
device = devinput
to
device = default

9. sudo /etc/init.d/lircd status reports errors like
Error: could not get file information for /dev/lirc0
After a lot of searching, found on this page that this could be because the driver lirc-rpi has been replaced with a newer version called gpio-ir, so that the /boot/config.txt line has to be changed from
dtoverlay=lirc-rpi
to
dtoverlay=gpio-ir
Did that, and it worked.
This is on Raspberry Pi 2 running Raspbian 9 (Stretch) with kernel 4.19.23+, running lirc version 0.9.4c-9 while the other Pi, which worked with dtoverlay=lirc-rpi was running Raspbian 9 (Stretch) with kernel 4.14.98-v7+ and the same lirc version  0.9.4c-9.

testing AppImages on various distros - dd iso to USB

As mentioned in my previous post, I had created an AppImage for distribution a Linux binary. Testing on 3 distros one generation earlier is recommended using chroot. For example,
https://www.pcsuggest.com/setup-a-32-bit-chroot-with-ubuntu-live-cd/

But I found the procedure for creating chroots to be more cumbersome than just dumping the Live distro iso into a USB pen drive, booting another machine from USB, and checking the AppImage on the distro.

1. Since I was on an Ubuntu-based Mint Linux 18.1, it had a "Startup Disk Creator" GUI app for dumping Ubuntu-like Live CD/DVD to USB devices.

2. For Fedora and OpenSuse, I used the following commandline, taking care to note the correct device id like /dev/sdc1 or /dev/sdd1 or whatever using mount,
sudo umount /dev/sdd*
sudo dd if=Fedora-Workstation-Live-x86_64-24-1.2.iso of=/dev/sdd bs=8M status=progress oflag=direct

3. This commandline pattern worked fine for Fedora and OpenSuse, since these isos were meant to work as Live CD/DVDs. So, I did not need to use unetbootin or anything like that for these. Approximately 3 MB per second to my USB drives, which were not very fast. 7-8 minutes to write 1.5 GB. 

creating an AppImage to distribute Linux binaries

Some notes of my AppImage creation process.


  1. First tried creating manually, using
    https://github.com/AppImage/docs.appimage.org/blob/master/source/packaging-guide/manual.rst and the AppRunx86-64 from https://github.com/AppImage/AppImageKit/releases
  2. Found and copied the libs it uses by doing the following to copy all shared libraries -https://www.commandlinefu.com/commands/view/10238/copy-all-shared-libraries-for-a-binary-to-directory
    ldd file | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /destination
  3. Need to use the environment variable $OWD (Original Working Directory) to get files from the OWD, like our ini file. This code snippet was a good template, https://stackoverflow.com/questions/40306012/c-using-environment-variables-for-paths
        char* pPath;
        pPath = getenv("PATH");
        if (pPath)
          std::cout << "Path =" << pPath << std::endl;
        return 0;
  4. Many libs copied with the manual method had to be excluded using the excludelist at
    https://github.com/AppImage/pkg2appimage/blob/master/excludelist
  5. Still did not work on newer distros. In this thread, probono recommended using trusty on TravisCI for building, and linuxdeployqt instead of manual creation of AppDir. Did that, and it worked. Far fewer libs are bundled by linuxdeployqt. Lists of the two bundles are available at this issue thread.
  6. The download link from transfer.sh can be seen if the entire log is downloaded from TravisCI.
  7. The travis yml file gives the outline of the build and bundling process.