Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Tutorial: Run Swift on Windows 10 the Easy Way (Using Linux Subsystem)

Posted: Wednesday, 7 September 2016

Running Apple's Swift programming language on Windows 10 is as simple as 1, 2 and 3.
  1. Setup the Linux Subsystem for Windows 10 Anniversary Edition
  2. Run sudo apt-get install build-essential (and optionally sudo apt-get install clang)
  3. Download, and Run swift!
  4. Note: for each of these links you can click or scroll down for more
Alternatively, the video below demonstrates the steps in motion...
https://www.youtube.com/embed/Z0PZc7WqPtE


And that's it.

Just note that both technologies are unstable as of September 2016
  • Swift is a fairly immature programming language
    • Due to the absence tools like a beautifier - though third-party tools such as Haaakon's SwiftFormat https://github.com/haaakon/SwiftFormat does the trick
    • Due to missing tangible desires such as bug reports & support from fellow Windows users of Swift (of which there is none)
    • And with breaking changes each major version of Swift (which might be why the Swift 1.0 code you found won't work on Swift 2.2 or even Swift 3.0 beta).
  • And the Windows Subsystem for Linux (WSL) is still in beta, with normally trivial tasks, such as interacting with the subsystem programmatically, almost impossible: https://github.com/Microsoft/BashOnWindows/issues/


Setting up WSL

To set up the Windows subsystem for Linux, an official guide can be followed here: https://msdn.microsoft.com/en-us/commandline/wsl/install_guide
Here's a summary:
  • Start Menu -> Search "Turn Windows features on or off"
  • Scroll Down to "Windows Subsystem for Linux (Beta)", and click the checkbox
  • Restart your computer, it should display a screen along the lines of "Configuring Windows", similar to a Windows Update
  • Once your computer has restarted, launch a normal Windows Command Prompt: Start Menu -> Search "Command Prompt" (or alternatively, cmd)
  • Type the command "bash", and press enter
  • Accept the T&C (or not, skipping this section and booting into Ubuntu is effectively the same)
  • Wait for the ~200MB Ubuntu Subsystem Image to Download, Extract and Install

And that's it! A mini non-Linux environment within Windows. Similar to how OS X does it, only 10 years behind.

Takes around 30 minutes.

Those Linux commands


With how administrative/root privileges work in WSL, you don't need "su/sudo" to run what are normally root commands (if you've skipped setting up the root user).
apt-get install build-essential should work on its own.
The build-essential package is required to run Swift. Without it, Swift would just fail in executing scripts. Unfortunately, this is quite a large package on Ubuntu, and even on Windows its no exception.
So run the command and wait it out, a tip to speed up the process of downloading packages is shown in the video.
Running apt-get install clang allows for Swift code compilation support in Windows via swiftc (swiftc with build-essentials alone does not work). Interestingly the resulting binary that swiftc compiles is a native Linux/Ubuntu ELF instead of a Windows exe.

Takes around 30 minutes.

Swift

Download Swift from here: https://swift.org/download/, note that you'd want the Ubuntu 14.04 version, if still offered.
Extract the archive just like you would on Ubuntu (or extract it using the Windows method, whichever you prefer), and run /usr/bin/swift through bash.

Takes around 10 minutes.


And that's it! Swift (the programming language) running on Windows 10 using the Windows Subsystem for Linux!

Although REPL doesn't really work, and you're not exactly working with native Windows goodness.




bchunk v1.2.1 - BinChunker for Windows

Posted: Monday, 8 August 2016

https://github.com/extramaster/bchunk
https://github.com/extramaster/bchunk/releases
https://github.com/extramaster/bchunk/releases/download/v1.2.1/bchunk.v1.2.1.zip
Edit: In case you're unsure of the VirusTotal results, cloning the repo and running "build.bat" (with MSVC - https://www.visualstudio.com/downloads/) should build the application
Otherwise, https://github.com/extramaster/bchunk/releases/download/v1.2.1_repub.1/bchunk.v1.2.1_repub.1.zip
VirusTotal: https://www.virustotal.com/en/file/22335fa68f60fc47378399d7039a778eebe268092c609d53066bf9478f994113/analysis/1476900472/

BinChunker is an application that converts .bin "Disc Image" files to .iso with the help of a .cue file.

The application is unfortunately Unix-only (which includes Mac OS X and Linux) due to the use of a number of non-standard C headers - in fact, the code will fail to compile on a Windows "cross-native" Linux layer like MingW64

$ gcc bchunk.c -o bchunk
bchunk.c:61:24: fatal error: netinet/in.h: No such file or directory
 #include <netinet/in.h>
                        ^
compilation terminated.

Fortunately, a fix has been published by mzex for use of BinChunker on Windows, however it does not come with the source code (only a binary encoded in base64 format).

In the spirit of the GPL, here's a copy of the source code on Github: https://github.com/extramaster/bchunk. Feel free to Fork (or even spin off as a separate repo).
And here's the Windows Binary Download of BinChunker, the GitHub releases system is used: https://github.com/extramaster/bchunk/releases.



Oh, and one more thing, the changes made do not break Linux/Unix builds. So you can compile this version with Linux as usual.





Better Python Standard Library Autocompletion for Notepad++

Posted: Thursday, 7 July 2016

Download: http://static.extramaster.net/python.xml.zip (476kb download - 3,367kb extracted)
Note that there's 13,563 definitions included, so any application that attempts to parse XML structure will have a bad time.

Before:


After:




Using the Notepad++ "python.xml" generator at: https://sourceforge.net/projects/npp-python/, in conjunction with a script that imports all Python modules: http://stackoverflow.com/questions/1206832/importing-the-entire-python-standard-library, on a computer with a fresh Python install, nabs a "python.xml" file with definitions and autocomplete entries for all Python Standard Library modules.


Download: http://static.extramaster.net/python.xml.zip
Or if github gists are your thing: https://gist.github.com/extramaster/9d0b7eba99a9708eb3f71ae95bcd42b5

The "python.xml" file should be placed in "C:\Program Files (x86)\Notepad++\plugins\APIs" or "C:\Program Files\Notepad++\plugins\APIs", overwriting the pre-installed copy.

In case you want to revert back to the pre-installed "python.xml" file, here's a copy: http://static.extramaster.net/python_original.xml.zip

Here's a list of all of the Python Standard Libraries used in the creation of the autocomplete file:
import _bsddb
import _ctypes
import _ctypes_test
import _elementtree
import _hashlib
import _msi
import _multiprocessing
import _socket
import _sqlite3
import _ssl
import _testcapi
import _tkinter
import bz2
import pyexpat
import select
import unicodedata
import winsound
import BaseHTTPServer
import Bastion
import CGIHTTPServer
import ConfigParser
import Cookie
import DocXMLRPCServer
import HTMLParser
import MimeWriter
import Queue
import SimpleHTTPServer
import SimpleXMLRPCServer
import SocketServer
import StringIO
import UserDict
import UserList
import UserString
import __future__
import _abcoll
import _osx_support
import _pyio
import _strptime
import _threading_local
import _weakrefset
import abc
import aifc
import antigravity
import anydbm
import argparse
import ast
import asynchat
import asyncore
import atexit
import audiodev
import base64
import bdb
import binhex
import bisect
import bsddb
import cProfile
import calendar
import cgi
import cgitb
import chunk
import cmd
import code
import codecs
import codeop
import collections
import colorsys
import commands
import compileall
import compiler
import contextlib
import cookielib
import copy
import copy_reg
import csv
import ctypes
import dbhash
import decimal
import difflib
import dircache
import dis
import distutils
import doctest
import dumbdbm
import dummy_thread
import dummy_threading
import email
import encodings
import filecmp
import fileinput
import fnmatch
import formatter
import fpformat
import fractions
import ftplib
import functools
import genericpath
import getopt
import getpass
import gettext
import glob
import gzip
import hashlib
import heapq
import hmac
import hotshot
import htmlentitydefs
import htmllib
import httplib
import idlelib
import ihooks
import imaplib
import imghdr
import importlib
import imputil
import inspect
import io
import json
import keyword
import lib2to3
import linecache
import locale
import logging
import macpath
import macurl2path
import mailbox
import mailcap
import markupbase
import md5
import mhlib
import mimetools
import mimetypes
import mimify
import modulefinder
import msilib
import multifile
import multiprocessing
import mutex
import netrc
import new
import nntplib
import ntpath
import nturl2path
import numbers
import opcode
import optparse
import os
import os2emxpath
import pdb
import pickle
import pickletools
import pipes
import pkgutil
import platform
import plistlib
import popen2
import poplib
import posixfile
import posixpath
import pprint
import profile
import pstats
import py_compile
import pyclbr
import pydoc
import pydoc_data
import quopri
import random
import re
import repr
import rexec
import rfc822
import rlcompleter
import robotparser
import runpy
import sched
import sets
import sgmllib
import sha
import shelve
import shlex
import shutil
import site
import smtpd
import smtplib
import sndhdr
import socket
import sqlite3
import sre
import sre_compile
import sre_constants
import sre_parse
import ssl
import stat
import statvfs
import string
import stringold
import stringprep
import struct
import subprocess
import sunau
import sunaudio
import symbol
import symtable
import sysconfig
import tabnanny
import tarfile
import telnetlib
import tempfile
import test
import textwrap
import this
import threading
import timeit
import toaiff
import token
import tokenize
import trace
import traceback
import types
import unittest
import urllib
import urllib2
import urlparse
import user
import uu
import uuid
import warnings
import wave
import weakref
import webbrowser
import whichdb
import wsgiref
import xdrlib
import xml
import xmllib
import xmlrpclib
import zipfile
import Canvas
import Dialog
import FileDialog
import FixTk
import ScrolledText
import SimpleDialog
import Tix
import Tkconstants
import Tkdnd
import Tkinter
import tkColorChooser
import tkCommonDialog
import tkFileDialog
import tkFont
import tkMessageBox
import tkSimpleDialog
import ttk
import turtle

Zbar 64bit for Python 2.7

Posted: Saturday, 25 June 2016

http://static.extramaster.net/zbar-0.10.win-amd64-py2.7.msi (build of: https://github.com/NaturalHistoryMuseum/ZBarWin64)

If your pip install of ZBar goes something along the lines of

Collecting zbar
  Using cached zbar-0.10.tar.bz2
Building wheels for collected packages: zbar
  Running setup.py bdist_wheel for zbar ... error
  Complete output from command "c:\program files (x86)\python27\python.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\andytr~1\\appdata\\local\\temp\\pip-build-dtzlas\\zbar\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d c:\users\andytr~1\appdata\local\temp\tmpq_wfxtpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_ext
  building 'zbar' extension
  creating build
  creating build\temp.win-amd64-2.7
  creating build\temp.win-amd64-2.7\Release
  C:\Users\Andy Tran\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-Ic:\program files (x86)\python27\include" "-Ic:\program files (x86)\python27\PC" /Tczbarmodule.c /Fobuild\temp.win-amd64-2.7\Release\zbarmodule.obj
  zbarmodule.c
  zbarmodule.c(65) : error C2143: syntax error : missing ';' before 'type'
  zbarmodule.c(66) : error C2065: 'major' : undeclared identifier
  zbarmodule.c(66) : error C2065: 'minor' : undeclared identifier
  zbarmodule.c(68) : error C2065: 'major' : undeclared identifier
  zbarmodule.c(68) : error C2065: 'minor' : undeclared identifier
  zbarmodule.c(133) : error C2275: 'zbar_error_t' : illegal use of this type as an expression
          c:\program files (x86)\python27\include\zbar.h(156) : see declaration of 'zbar_error_t'
  zbarmodule.c(133) : error C2146: syntax error : missing ';' before identifier 'ei'
  zbarmodule.c(133) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(134) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(134) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(134) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(135) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(135) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(136) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(146) : error C2275: 'PyObject' : illegal use of this type as an expression
          c:\program files (x86)\python27\include\object.h(108) : see declaration of 'PyObject'
  zbarmodule.c(146) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(147) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(151) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(151) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(151) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(152) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(152) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(152) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(153) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(153) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(153) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(154) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(154) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(154) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(155) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(155) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(155) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(156) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(156) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(156) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(157) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(157) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(157) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(158) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(158) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(158) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(159) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(159) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(159) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(160) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(160) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(160) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(162) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(162) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(162) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(163) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(164) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(164) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(164) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
  zbarmodule.c(164) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(164) : error C2065: 'ei' : undeclared identifier
  zbarmodule.c(167) : error C2275: 'PyObject' : illegal use of this type as an expression
          c:\program files (x86)\python27\include\object.h(108) : see declaration of 'PyObject'
  zbarmodule.c(167) : error C2065: 'dict' : undeclared identifier
  zbarmodule.c(167) : error C2065: 'mod' : undeclared identifier
  zbarmodule.c(167) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(167) : warning C4024: 'PyModule_GetDict' : different types for formal and actual parameter 1
  zbarmodule.c(169) : error C2065: 'dict' : undeclared identifier
  zbarmodule.c(169) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(169) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(171) : error C2065: 'dict' : undeclared identifier
  zbarmodule.c(171) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(171) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(183) : error C2275: 'PyObject' : illegal use of this type as an expression
          c:\program files (x86)\python27\include\object.h(108) : see declaration of 'PyObject'
  zbarmodule.c(183) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(185) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(185) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(185) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(186) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(186) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(186) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(187) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(187) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(187) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(188) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(188) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(188) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(189) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(189) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(189) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(190) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(190) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(190) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(191) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(191) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(191) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(192) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(192) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(192) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(193) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(193) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(193) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(194) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(194) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(194) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(195) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(195) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(195) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(196) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(196) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(196) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  zbarmodule.c(197) : error C2065: 'tp_dict' : undeclared identifier
  zbarmodule.c(197) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
  zbarmodule.c(197) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
  error: command 'C:\\Users\\Andy Tran\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2

  ----------------------------------------
  Failed building wheel for zbar
  Running setup.py clean for zbar
Failed to build zbar
Installing collected packages: zbar
  Running setup.py install for zbar ... error
    Complete output from command "c:\program files (x86)\python27\python.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\andytr~1\\appdata\\local\\temp\\pip-build-dtzlas\\zbar\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\andytr~1\appdata\local\temp\pip-6cbwmc-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'zbar' extension
    creating build
    creating build\temp.win-amd64-2.7
    creating build\temp.win-amd64-2.7\Release
    C:\Users\Andy Tran\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-Ic:\program files (x86)\python27\include" "-Ic:\program files (x86)\python27\PC" /Tczbarmodule.c /Fobuild\temp.win-amd64-2.7\Release\zbarmodule.obj
    zbarmodule.c
    zbarmodule.c(65) : error C2143: syntax error : missing ';' before 'type'
    zbarmodule.c(66) : error C2065: 'major' : undeclared identifier
    zbarmodule.c(66) : error C2065: 'minor' : undeclared identifier
    zbarmodule.c(68) : error C2065: 'major' : undeclared identifier
    zbarmodule.c(68) : error C2065: 'minor' : undeclared identifier
    zbarmodule.c(133) : error C2275: 'zbar_error_t' : illegal use of this type as an expression
            c:\program files (x86)\python27\include\zbar.h(156) : see declaration of 'zbar_error_t'
    zbarmodule.c(133) : error C2146: syntax error : missing ';' before identifier 'ei'
    zbarmodule.c(133) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(134) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(134) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(134) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(135) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(135) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(136) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(146) : error C2275: 'PyObject' : illegal use of this type as an expression
            c:\program files (x86)\python27\include\object.h(108) : see declaration of 'PyObject'
    zbarmodule.c(146) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(147) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(151) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(151) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(151) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(152) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(152) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(152) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(153) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(153) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(153) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(154) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(154) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(154) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(155) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(155) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(155) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(156) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(156) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(156) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(157) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(157) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(157) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(158) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(158) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(158) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(159) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(159) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(159) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(160) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(160) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(160) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(162) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(162) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(162) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(163) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(164) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(164) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(164) : warning C4024: 'PyModule_AddObject' : different types for formal and actual parameter 1
    zbarmodule.c(164) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(164) : error C2065: 'ei' : undeclared identifier
    zbarmodule.c(167) : error C2275: 'PyObject' : illegal use of this type as an expression
            c:\program files (x86)\python27\include\object.h(108) : see declaration of 'PyObject'
    zbarmodule.c(167) : error C2065: 'dict' : undeclared identifier
    zbarmodule.c(167) : error C2065: 'mod' : undeclared identifier
    zbarmodule.c(167) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(167) : warning C4024: 'PyModule_GetDict' : different types for formal and actual parameter 1
    zbarmodule.c(169) : error C2065: 'dict' : undeclared identifier
    zbarmodule.c(169) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(169) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(171) : error C2065: 'dict' : undeclared identifier
    zbarmodule.c(171) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(171) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(183) : error C2275: 'PyObject' : illegal use of this type as an expression
            c:\program files (x86)\python27\include\object.h(108) : see declaration of 'PyObject'
    zbarmodule.c(183) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(185) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(185) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(185) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(186) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(186) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(186) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(187) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(187) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(187) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(188) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(188) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(188) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(189) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(189) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(189) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(190) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(190) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(190) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(191) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(191) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(191) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(192) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(192) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(192) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(193) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(193) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(193) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(194) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(194) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(194) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(195) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(195) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(195) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(196) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(196) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(196) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    zbarmodule.c(197) : error C2065: 'tp_dict' : undeclared identifier
    zbarmodule.c(197) : warning C4047: 'function' : 'PyObject *' differs in levels of indirection from 'int'
    zbarmodule.c(197) : warning C4024: 'zbarEnumItem_New' : different types for formal and actual parameter 1
    error: command 'C:\\Users\\Andy Tran\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2

    ----------------------------------------
Command ""c:\program files (x86)\python27\python.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\andytr~1\\appdata\\local\\temp\\pip-build-dtzlas\\zbar\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\andytr~1\appdata\local\temp\pip-6cbwmc-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\andytr~1\appdata\local\temp\pip-build-dtzlas\zbar\

And if building "ZBarWin64" got you nowhere:

>python setup.py build
running build
running build_ext
building 'zbar' extension
creating build
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tczbarmodule.c /Fobuild\temp.win-amd64-2.7\Release\zbarmodule.obj
zbarmodule.c
zbarmodule.c(121): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcenum.c /Fobuild\temp.win-amd64-2.7\Release\enum.obj
enum.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcexception.c /Fobuild\temp.win-amd64-2.7\Release\exception.obj
exception.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcsymbol.c /Fobuild\temp.win-amd64-2.7\Release\symbol.obj
symbol.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcsymbolset.c /Fobuild\temp.win-amd64-2.7\Release\symbolset.obj
symbolset.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcsymboliter.c /Fobuild\temp.win-amd64-2.7\Release\symboliter.obj
symboliter.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcimage.c /Fobuild\temp.win-amd64-2.7\Release\image.obj
image.c
image.c(254): warning C4244: 'initializing': conversion from 'Py_ssize_t' to 'unsigned int', possible loss of data
image.c(329): warning C4244: 'function': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcprocessor.c /Fobuild\temp.win-amd64-2.7\Release\processor.obj
processor.c
processor.c(249): warning C4244: '=': conversion from 'double' to 'int', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcimagescanner.c /Fobuild\temp.win-amd64-2.7\Release\imagescanner.obj
imagescanner.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcdecoder.c /Fobuild\temp.win-amd64-2.7\Release\decoder.obj
decoder.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-IC:\Program Files (x86)\Python27\include" "-IC:\Program Files (x86)\Python27\PC" /Tcscanner.c /Fobuild\temp.win-amd64-2.7\Release\scanner.obj
scanner.c
creating build\lib.win-amd64-2.7
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO "/LIBPATH:C:\Program Files (x86)\Python27\libs" "/LIBPATH:C:\Program Files (x86)\Python27\PCbuild\amd64" zbar.lib /EXPORT:initzbar build\temp.win-amd64-2.7\Release\zbarmodule.obj build\temp.win-amd64-2.7\Release\enum.obj build\temp.win-amd64-2.7\Release\exception.obj build\temp.win-amd64-2.7\Release\symbol.obj build\temp.win-amd64-2.7\Release\symbolset.obj build\temp.win-amd64-2.7\Release\symboliter.obj build\temp.win-amd64-2.7\Release\image.obj build\temp.win-amd64-2.7\Release\processor.obj build\temp.win-amd64-2.7\Release\imagescanner.obj build\temp.win-amd64-2.7\Release\decoder.obj build\temp.win-amd64-2.7\Release\scanner.obj /OUT:build\lib.win-amd64-2.7\zbar.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\zbar.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\zbar.pyd.manifest
LINK : fatal error LNK1181: cannot open input file 'zbar.lib'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\link.exe' failed with exit status 1181

Then you can build this awesome fork instead: https://github.com/NaturalHistoryMuseum/ZBarWin64

Or you can get a pre-built Windows installer here: http://static.extramaster.net/zbar-0.10.win-amd64-py2.7.msi


Caps/Scroll/Num Lock Toggler for Windows

Posted: Friday, 20 November 2015

Skip to download section

If you have a keyboard that does not have built-in Scroll Lock/Num Lock capabilities (such as the Microsoft Wireless Arc Keyboard - pictured below),

Then here’s a program that will toggle Scroll Lock/Caps Lock and Num Lock via software.

Download

http://static.extramaster.net/KeyboardLockTool.exe (413KB)

MD5: A7D6EF9C0A528C28198CEE4C907A8671
SHA-256: F90F46A618D70C1436DD9ABA38EA9F68B2CCCC354274E63FAF3B82B1344C8DA7

VirusTotal Scan:
https://www.virustotal.com/en/file/f90f46a618d70c1436dd9aba38ea9f68b2cccc354274e63faf3b82b1344c8da7/analysis/1447947391/
Works with Windows 10. A wired keyboard with Num lock/Scroll lock/Caps lock LEDs light up, indicating that this program is not hardware-dependent.

Demo

Tags:
windows force scroll lock
microsoft wireless keyboard scroll lock
microsoft arc keyboard scroll lock
trigger scroll lock without keyboard
trigger scroll lock

Python: Creating a timed image slideshow with PIL and OpenCV v2

Posted: Friday, 17 July 2015

Problem

Apparently, one of the hardest video-editing task to do with a script is to create a dynamically-timed slideshow without any fancy-drag and drop GUIs.


With Adobe After Effects, you cannot dynamically load external images using an expression (they will need to be loaded into your project beforehand, and even then, you cannot load the image into a comp with an expression).

And adding hundreds of layers of images and having to go through each and every one of them to edit the expression is a fairly tedious task.

Worse of all, every change that you make - such as adding a new image to the slideshow  - will compound towards the chore of doing things manually.


Solution

Building upon my last two posts: Python: Converting from PIL to OpenCV 2 Image Formats and Python: PIL to mp4, we've reached the end.

With "Python: PIL to mp4", a simple blending transition was created using PIL and OpenCV, But the objective of this post is to introduce timings to delay the animation for numerous/multiple images.

We can extend this idea of having a primitive transition to allow for an image to be delayed from transitioning until a certain amount of time has elapsed, and to allow the transition to occur after "x" amount of seconds, hence forming a slideshow.


Process

Initialization

So to start off with, we're going to need some data to work with.
Since it's Python, you can do whatever you want to feed data in - you could use a JSON file, CSV, Pickle, whatever you're comfortable with, or perhaps, whatever arbitrary file format that you're locked into using.

But here, a basic python array will be used to indicate the timings and image file that will be fed into the slideshow, amongst other data...
songData = [
    [390, u'Fractal', u'Itvara', 'minimix', u'image1.jpg'],
    [322, u'Case & Point', u'Error Code', 'minimix', u'image2.jpg'],
    [261, u'Excision & Pegboard Nerds', u'Bring the Madness (Noisestorm Remix) [feat. Mayor Apeshit]', 'minimix', u'image3.jpg'],
    [157, u'Nitro Fun', u'Final Boss', 'minimix', u'image4.jpg'],
    [88, u'Astronaut', u'Quantum (Virtual Riot Remix)', 'minimix', u'image5.jpg'],
    [0, u'Fractal', u'Contact', 'minimix', u'image6.jpg']]

As you can see in the data above, the most relevant data is songData[][0] and songData[][4], indicating the timings (in seconds) and the image file locations, respectively.

We're going to set the FPS of the slideshow... 60FPS is the standard nowadays, so we're going to set that and process the songData above to reflect this...
FPS = 60 # Sets the FPS of the entire video
currentFrame = 0 # The animation hasn't moved yet, so we're going to leave it as zero
startFrame = 0 # The animation of the "next" image starts at "startFrame", at most
trailingSeconds = 5 # Sets the amount of time we give our last image (in seconds)
blendingDuration = 3.0 # Sets the amount of time that each transition should last for
                       # This could be more dynamic, but for now, a constant transition period is chosen
blendingStart = 10 # Sets the time in which the image starts blending before songFile

for i in songData:
    i[0] = i[0] * FPS # Makes it so that iterating frame-by-frame will result in properly timed slideshows

Now the first image is going to be loaded in by the script - as so:
im1 = Image.open(songData[-1][4]) # Load the image in
im2 = im1 # Define a second image to force a global variable to be created

current = songData[-1][4] # We're going to let the script know the location of the current image's location
previous = current # And this is to force/declare a global variable

And next up is to create the actual OpenCV video handling capability. You can have a read-up about this here: Python: PIL to mp4
height, width, layers = np.array(im1).shape # Get some stats on the image file to create the video with
video = cv2.VideoWriter("slideshow.avi",-1,60,(width,height),True)

So that was the basic initialization routine. If you don't get how it works together yet, don't worry. Just read on - as the full code with everything combined is below.

Main loop

So the strategy behind generating this slideshow is to loop through each and every frame and continuously feed that into our output video file. Sure some corners can be cut - by which you only generate the transitions (leaving the gaps to be manually filled by an external program) - but this post is looking more into automating the entire slideshow generation process with only Python, PIL and OpenCV.

We're going to have a main while loop that sets the limit on how long our slideshow should last.
while currentFrame < songData[0][0] + FPS * 60 * trailingSeconds: # RHS defines the limit of the slideshow

And this is where the nitty gritty kicks in: the actual code that makes the transition between each image within the slideshow...
    for i in songData: # Loop through each image timing
        if currentFrame >= i[0] - (blendingStart * FPS): # If the image timing happens to be for the
                                                         # current image, the continue on...
                                                         # (Notice how songData is reversed)
                                                         
            # The print statement adds some verbosity to the program
            print str(currentFrame) + " - " + str(i[0] - (blendingStart * FPS)) + " - " + i[2]
            if not current == i[4]: # Check if the image file has changed
                previous = current # We'd want the transition to start if the file has changed
                current = i[4]
                startFrame = i[0] - (blendingStart * FPS)

                # The two images in question for the blending is loaded in
                im1 = Image.open(previous)
                im2 = Image.open(current)
            break

    # See: http://blog.extramaster.net/2015/07/python-pil-to-mp4.html for the part below
    diff = Image.blend(im1, im2, min(1.0, (currentFrame - startFrame) / float(FPS) / blendingDuration))
    video.write(cv2.cvtColor(np.array(diff), cv2.COLOR_RGB2BGR))
    
    currentFrame += 1 # Next frame
The ending to this program is pretty self-explanatory...
# At this point, we'll assume that the slideshow has completed generating, and we want to close everything off to prevent a corrupted output.
video.release()


All together now!

So here's all the code required to create a timed image slideshow with PIL and OpenCV v2!

Code:
from PIL import Image
import cv2
import numpy as np

songData = [
    [390, u'Fractal', u'Itvara', 'minimix', u'image1.jpg'],
    [322, u'Case & Point', u'Error Code', 'minimix', u'image2.jpg'],
    [261, u'Excision & Pegboard Nerds', u'Bring the Madness (Noisestorm Remix) [feat. Mayor Apeshit]', 'minimix', u'image3.jpg'],
    [157, u'Nitro Fun', u'Final Boss', 'minimix', u'image4.jpg'],
    [88, u'Astronaut', u'Quantum (Virtual Riot Remix)', 'minimix', u'image5.jpg'],
    [0, u'Fractal', u'Contact', 'minimix', u'image6.jpg']]

FPS = 60 # Sets the FPS of the entire video
currentFrame = 0 # The animation hasn't moved yet, so we're going to leave it as zero
startFrame = 0 # The animation of the "next" image starts at "startFrame", at most
trailingSeconds = 5 # Sets the amount of time we give our last image (in seconds)
blendingDuration = 3.0 # Sets the amount of time that each transition should last for
                       # This could be more dynamic, but for now, a constant transition period is chosen
blendingStart = 10 # Sets the time in which the image starts blending before songFile

for i in songData:
    i[0] = i[0] * FPS # Makes it so that iterating frame-by-frame will result in properly timed slideshows

im1 = Image.open(songData[-1][4]) # Load the image in
im2 = im1 # Define a second image to force a global variable to be created

current = songData[-1][4] # We're going to let the script know the location of the current image's location
previous = current # And this is to force/declare a global variable

height, width, layers = np.array(im1).shape # Get some stats on the image file to create the video with
video = cv2.VideoWriter("slideshow.avi",-1,60,(width,height),True)

while currentFrame < songData[0][0] + FPS * 60 * trailingSeconds: # RHS defines the limit of the slideshow
    for i in songData: # Loop through each image timing
        if currentFrame >= i[0] - (blendingStart * FPS): # If the image timing happens to be for the
                                                         # current image, the continue on...
                                                         # (Notice how songData is reversed)
                                                         
            # The print statement adds some verbosity to the program
            print str(currentFrame) + " - " + str(i[0] - (blendingStart * FPS)) + " - " + i[2]
            if not current == i[4]: # Check if the image file has changed
                previous = current # We'd want the transition to start if the file has changed
                current = i[4]
                startFrame = i[0] - (blendingStart * FPS)

                # The two images in question for the blending is loaded in
                im1 = Image.open(previous)
                im2 = Image.open(current)
            break

    # See: http://blog.extramaster.net/2015/07/python-pil-to-mp4.html for the part below
    diff = Image.blend(im1, im2, min(1.0, (currentFrame - startFrame) / float(FPS) / blendingDuration))
    video.write(cv2.cvtColor(np.array(diff), cv2.COLOR_RGB2BGR))
    
    currentFrame += 1 # Next frame

# At this point, we'll assume that the slideshow has completed generating, and we want to close everything off to prevent a corrupted output.
video.release()



Sample output

So with all the code above, it begs the question, why do I need to create a slideshow using scripts?
Well, here's a little sample of what you can do with a simple little slideshow.
Note the timings from "songData",
songData = [
    [390, u'Fractal', u'Itvara', 6:30, u'image1.jpg'],
    [322, u'Case & Point', u'Error Code', 6:22, u'image2.jpg'],
    [261, u'Excision & Pegboard Nerds', u'Bring the Madness (Noisestorm Remix) [feat. Mayor Apeshit]', 4:21, u'image3.jpg'],
    [157, u'Nitro Fun', u'Final Boss', 2:37, u'image4.jpg'],
    [88, u'Astronaut', u'Quantum (Virtual Riot Remix)', 1:28, u'image5.jpg'],
    [0, u'Fractal', u'Contact', 0, u'image6.jpg']]
With this slideshow, you can really enhance the effect of audio-react "music" YouTube videos, especially Youtube Music Mixes, like this:
Direct Link: https://www.youtube.com/watch?v=XI25k5Z-t88
Direct Link: https://www.youtube.com/watch?v=XI25k5Z-t88



Python: PIL to mp4

Posted: Friday, 10 July 2015

Why?

If you're having trouble piping image data frame-by-frame into FFMpeg (with the subprocess module), you may be interested in another way to convert python image data into a movie without having to store each individual frame as a file (whether it be .png, .jpg, .gif sequences).

However, this method is a little more complicated then attempting to get FFMpeg to work with python, so here's a little scenario to help with whether or not this tutorial is for you.

Let's say you're in a scenario, where you've encountered one of these errors:
"AttributeError: 'Popen' object has no attribute 'proc'"
"IOError: [Errno 22] Invalid argument"
and even
"IOError: [Errno 32] Broken pipe"

Either resulting from this tutorial: Read and write video frames in Python using FFMPEG - __del__( self ) or from some code elsewhere, and you are willing to use an alternative to ffmpeg to convert your PIL images to a video format like in this case: python - Piped FFMPEG won't write frames correctly - Stack Overflow, then read on.

If you're not willing to switch from FFMpeg to another alternative then press backspace and keep on searching!


How?

To do this, we're going to employ the assistance of OpenCV v2 and NumPy, which has been covered here: Python: Converting from PIL to OpenCV 2 Image Formats

Please note that the OpenCV version used is version 2, which uses
import cv2
as the import statement, as opposed to something like
import cv
There may be an update to OpenCV that breaks the code like with the answer found in the following link. image - Python JPEG to movie - Stack Overflow.
But without further ado, let's jump right into it!


Imports

We're going to be using PIL for loading and manipulating the images, NumPy for a PIL-to-OpenCV bridge, and OpenCV Version 2 for the actual image-to-movie process.
So our imports will look something like
from PIL import Image
import numpy, cv2


Manipulation

Obviously, the purpose of using python to convert from PIL to a movie is to be able to manipulate the image frame-by-frame using the power of PIL.
So here, I'm going to demonstrate some basic image blending functionality, just to provide a basis for this tutorial.

Here, we have two images, demo3_1.jpg and demo3_2.jpg...
demo3_1.jpg
demo3_2.jpg

With PIL, you can do something like

# Imports can be found in the "Imports" section above

# Load up the first and second demo images
image1 = Image.open("demo3_1.jpg")
image2 = Image.open("demo3_2.jpg")

# Create a new image which is the half-way blend of image1 and image2
# The "0.5" parameter denotes the half-way point of the blend function.
images1And2 = Image.blend(image1, image2, 0.5)

# Save the resulting blend as a file
images1And2.save("demo3_3.jpg")

In order to use PIL to blend two images together, in this case, the two images are blended at the halfway point, which means that half of each image is merged to become the resultant blended image.
demo3_3.jpg
This is a primitive version of an "additive blend", so you can think of it as an "additive frame blending using PIL" - note also that ImageChops isn't used for simplicity, but that's some additional power that you can use to manipulate images with.


Writing a video with OpenCV

With OpenCV, there's a "VideoWriter" method which you can access to create a movie with.
The method goes something like this:
video = cv2.VideoWriter(filename, codec selection, frames per second, (width, height))
Writing to the VideoWriter can be done with "video.write( numpy array as string )", and the VideoWriter can be "closed" by using "video.release()".

And that's all you need to know to convert from PIL to mp4 (or at least a movie, you need a certain codec for conversion to mp4).


All together now

With all the elements from the sections above in mind, here's the code in action
# Imports can be found in the "Imports" section above

# Load up the first and second demo images, assumed is that image1 and image2 both share the same height and width
image1 = Image.open("demo3_1.jpg")
image2 = Image.open("demo3_2.jpg")

# Grab the stats from image1 to use for the resultant video
height, width, layers =  numpy.array(image1).shape

# Create the OpenCV VideoWriter
video = cv2.VideoWriter("demo3_4.avi", # Filename
                        -1, # Negative 1 denotes manual codec selection. You can make this automatic by defining the "fourcc codec" with "cv2.VideoWriter_fourcc"
                        10, # 10 frames per second is chosen as a demo, 30FPS and 60FPS is more typical for a YouTube video
                        (width,height) # The width and height come from the stats of image1
                        )

# We'll have 30 frames be the animated transition from image1 to image2. At 10FPS, this is a whole 3 seconds
for i in xrange(0,30):
    images1And2 = Image.blend(image1, image2, i/30.0)

    # Conversion from PIL to OpenCV from: http://blog.extramaster.net/2015/07/python-converting-from-pil-to-opencv-2.html
    video.write(cv2.cvtColor(numpy.array(images1And2), cv2.COLOR_RGB2BGR))

# And back from image2 to image1...
for i in xrange(0,30):
    images2and1 = Image.blend(image2, image1, i/30.0)
    video.write(cv2.cvtColor(numpy.array(images2and1), cv2.COLOR_RGB2BGR))

# Release the video for it to be committed to a file
video.release()
Note that when you run the code above, you'll get a prompt for codec selection...
It is possible to find a codec for direct .mp4 conversions, however here, the default "Intel IYUV" codec was chosen and used.

From this stage as well, you can use FFMpeg (outside of Python) or your favourite video conversion program to convert from the codec that you selected to the format that you want, which can indeed include .mp4 files... ImageMagick was used to convert the output to the gif below:



And that's it!




Note that this post was made specifically for OpenCV v2, as documentation online were frustratingly for OpenCV v1, which has different methods and such.

As a disclaimer, things might change in a newer version of OpenCV, so this information is correct as of July 2015.



Covered Topics:
PIL to mp4 conversion
PIL to movie conversion
PIL/Python/OpenCV Video file from Images
PIL/Python/OpenCV JPEG to movie
Creating an OpenCV movie from PIL images
Converting an OpenCV movie into PIL Images

Python: Converting from PIL to OpenCV 2 Image Formats

Code: opencvImage = numpy.array(PILImage)


Suppose you have an image that has been manipulated with the Python Imaging Library, and you want to convert that image into a format that can be understood by the OpenCV Version 2 Library.

To do that, as of OpenCV v2, you can use the NumPy array as an intermediary format between the two libraries, where NumPy can convert PIL data into the NumPy array format, and OpenCV v2 can recognize the NumPy array natively.

To demonstrate this conversion, here's some code.


# First you need to import the libraries in question.
import numpy
import cv2
from PIL import Image

# And then you need a PIL image to work with, for now, an image from a local file is going to be used.
PILImage = Image.open("demo1.jpg")

demo1.jpg
# The conversion from PIL to OpenCV is done with the handy NumPy method "numpy.array" which converts the PIL image into a NumPy array. opencvImage = numpy.array(PILImage) # Display the OpenCV image using inbuilt methods. cv2.imshow('Demo Image',opencvImage) cv2.waitKey(0) cv2.destroyAllWindows() # Which results in:
However, as you can see in the demonstration, the output OpenCV image turned a little weird, with the colour not matching the original PIL image (in the sense that the OpenCV image having the wrong colours). You can try this out for yourself...

This is because we're dealing with a multi-channel/"RGB" format and not a single channel image file, and a conversion from PIL to OpenCV involves a little bit of additional translation, this can be solved with OpenCV's "cvtColor" method.

Code: opencvImage = cv2.cvtColor(numpy.array(PILImage), cv2.COLOR_RGB2BGR)
To demonstrate this additional translation, here's some code.



# First you need to import the libraries in question.
import numpy
import cv2
from PIL import Image

# And then you need a PIL image to work with, for now, an image from a local file is going to be used.
PILImage = Image.open("demo2.jpg")

demo2.jpg
# The conversion from PIL to OpenCV is done with the handy NumPy method "numpy.array" which converts the PIL image into a NumPy array. # cv2.cvtColor does the trick for correcting the colour when converting between PIL and OpenCV Image formats via NumPy. opencvImage = cv2.cvtColor(numpy.array(PILImage), cv2.COLOR_RGB2BGR) # Display the OpenCV image using inbuilt methods. cv2.imshow('Demo 2 Image',opencvImage) cv2.waitKey(0) cv2.destroyAllWindows() # Which results in:

And that's it!
Note that this post was made specifically for OpenCV v2, as documentation online were frustratingly for OpenCV v1, which has different methods and such.

As a disclaimer, things might change in a newer version of OpenCV, so this information is correct as of July 2015.



Covered Topics:
PIL to NumPy conversion
PIL to cv2 conversion
PIL to OpenCV conversion
Adaptors.PIL2Ipl alternative/replacement/not working
Creating an OpenCV image from a PIL image
Converting an OpenCV image into a PIL Image

How to fix Microsoft Mobile Mouse Wheel Scrolling problems

Posted: Saturday, 27 June 2015

Table of Contents

Pre-solution

What didn't work

Dealing with the scrolling issues with the Microsoft Mobile 3500 Mouse turned out to be fairly simple, but


  • After plenty of messy registry hacks
    • (changing HCKU\Control Panel\Desktop\WheelScrollLinesHCKU\Control Panel\Mouse keys didn't work)
  • After plenty of time spent messing around with Control Panel
    • The basic "tutorials" only show you how to change the amount of lines scrolled at a time, but does not deal with the problem regarding the mouse scroll wheel sensitivity
  • After restarting/logging off a few times (logging off is apparently supposed to apply the registry changes that you've made)
  • And even after re-plugging the nano-transceiver device,


Nothing seemed to work to fix the delayed/slow scrolling with the Microsoft Mouse...

Fixing Proxy/Loading Issues with the Windows 8 App Store

Posted: Monday, 6 April 2015

This is the Windows Store app. Or, at least it would be if it worked. For now, it's just a splash screen...

Well, if would still be a splash screen if it wasn't for the fact that after a long wait, an error message appears.

The one I got first was:

We weren't able to connect to the Store. This might have happened because of a server problem or the network connection might have timed out. Please wait a few minutes and try again. (0x80072ee2)

The next attempt in opening the store app resulted in another error:

We weren't able to connect to the Store. This might have happened because of a server problem or the network connection might have timed out. Please wait a few minutes and try again. (0x80190190)

Note how, in both cases, the error code was different...

So if you're currently encountering an error message with the same error codes, then you're in luck, since there is a fix! If the error code and problem is similar (but not exactly the same) then in any case just have a read through and see if your problem gets fixed.


CHM file isn't working on Windows

Posted: Monday, 1 December 2014

If you've ever dealt with CHM files, then you would already know that those letters are short for "Compiled HTML", which are typically used as a resource to HELP or guide users through a particular set of problems.

Tutorial: Compile Python to EXE

Posted: Monday, 15 September 2014

Click here to skip to the decompiling py2exe section
Click here to skip to the compiling Python to EXE section
Questions? Comment Section Link Here

Introduction

So we all know Python. Its a fun extension to the C language (Read: a language built on top of C). But one question, is, why can't we compile Python into an exe file, just like with C?

Now Python is an interesting language, in that it is both compiled and interpreted. In fact, there are many different implementations of the language. We have PyPy, on one hand, which does both, IronPython, which is basically a .NET compiler for Python, but the main focus is on CPython - Or what we all know as "Python". CPython is the "main reference implementation" of Python, and is the "Python" that is downloaded at https://www.python.org/.

It's weird to think that "Python" is not just Python, but makes sense considering the fact that Python is open source. A similar comparison between PyPy/IronPython and CPython can be made with JavaScript (js), where js is implemented not as "JavaScript", but as V8, spidermonkey, rhino and much more. We've come a long way from the monopoly that Microsoft has from their own programming languages, C#, VB.net and VBScript.

Hiding Drives in Windows

Posted: Thursday, 4 September 2014




If you're finding a way to hide hard drives on windows xp, 7, 8, 8.1 or any other windows devices, then there's a simple solution that doesn't involve installing or running third party programs.
In fact, if you've looked around, then the only feasible option is to use the windows registry to set flags on which hard drive to hide inside of explorer.

Disclaimer: Using the registry is dangerous, however its the lesser of evils between the choices of hacking about with the group policy (which you can't actually do without Windows 7 basic, starter and home premium, e.t.c., using command prompt to fiddle around with an even more volatile environment.
Make sure you backup your registry before continuing (for when something goes wrong now, or in the future).
So, with registry hacking, what about the big wall of text with all of those fancy numbers and what not?
A list of numbers without any immediate use. Source: ghacks.net
Well, lets skip the big wall of numbers and have a nice clickable online site that deals with this: http://extramaster.net/tools/windowsDriveCalculator/
The steps showing how the steps works is as follows.

#0 Start with an empty registry with everything remaining untouched.

Note: You don't have to navigate here, or perform this step AT ALL while using the tool - there may as well be already something here... It doesn't really matter...

#1 Find and identify the drives that you want to remove


Being a triple-quadruple boot install, no drives other then the C:\ drive is actually needed to be visible...

#2 Visit the page

You'll be greeted with something like this...

#3 Select the drives that you want to hide

#4.5 Click on the "Download" link/button to download

"Keep" the file, and then open it...

I wasn't able to screenshot the following dialogue box in Windows 7, but here's what you have to do in Windows 8.1...

#4.5.1 Run the file when the security warning pops up

#4.5.2 Accept the dialogue boxes that follow

#5 Restart Windows or log off and log back in

#6 Enjoy less hard drives cluttering explorer!

Advanced Query Syntax (AQS) is not powerful enough!

Posted: Tuesday, 19 August 2014

Windows 7 came with a nifty feature called AQS which allowed users to search files and folders based upon rules and expressions.
This functionality was extended to Windows 8 and Windows 8.1, where the syntax and concept have remained intact.
Compared to regular expressions, AQS have yet to realise its "Advanced" claim, and should really fashion itself as the "Basic Query Syntax (BQS)".
Consider this scenario. I have a list of archives that I want to search through on my computer. These archives have a specific naming structure, 01-01-01 Archive.rar, 02-01-01 Archive.rar, 03-01-01 Archive.rar... Basically following the pattern of "DD-MM-YY Name.rar"
With "AQS", you're allowed to use the AND and OR operators, where to achieve searching the said files, you could hypothetically do something like: (0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9) and (0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9) * type:.rar

Well.. This worked in Windows 7. But, since Windows 8.1 is the trend now, I updated my computer and found out that it no longer worked.

The question to be asked. Is why is it so complicated to search numbers in the first place?
  • (0-9) and (0-9) * type:.rar
  • [0-9] and [0-9] * type:.rar
  • title:(0-9) and (0-9) * type:.rar
  • title:[0-9] and [0-9] * type:.rar
  • (0-9)(0-9) * type:.rar
  • [0-9][0-9] * type:.rar
  • (0-100) * type:.rar
  • [0-100] * type:.rar
  • title:(0-100) * type:.rar
  • title:[0-100] * type:.rar
All do not work...

With regular expressions, the following works fine:

However, the same regular expression fails completely in Windows 8.1...

The best solution that I could come up to solve my problem was to use the following AQS query: ("00" OR "01" OR "02" OR "03" OR "04" OR "05" OR "06" OR "07" OR "08" OR "09" OR "10" OR "11" OR "12" OR "13" OR "14" OR "15" OR "16" OR "17" OR "18" OR "19" OR "20" OR "21" OR "22" OR "23" OR "24" OR "25" OR "26" OR "27" OR "28" OR "29" OR "30" OR "31")

Though, I guess when it comes down to it, this is just proof that the "Advanced Query Syntax" format is simply not powerful enough.