Update opencv code to work better with gui