mirror of
https://github.com/opencv/opencv.git
synced 2025-06-08 01:53:19 +08:00
Define execfile, file, long, raw_input, xrange for Python 3
This commit is contained in:
parent
60e5e213fd
commit
8a79b167b8
@ -29,6 +29,12 @@ try:
|
|||||||
except NameError:
|
except NameError:
|
||||||
unicode = lambda s: str(s)
|
unicode = lambda s: str(s)
|
||||||
|
|
||||||
|
try:
|
||||||
|
xrange # Python 2
|
||||||
|
except NameError:
|
||||||
|
xrange = range # Python 3
|
||||||
|
|
||||||
|
|
||||||
if re.search("windows", platform.system(), re.I):
|
if re.search("windows", platform.system(), re.I):
|
||||||
try:
|
try:
|
||||||
import _winreg
|
import _winreg
|
||||||
@ -600,7 +606,7 @@ def template(fileName, svg, replaceme="REPLACEME"):
|
|||||||
|
|
||||||
def load(fileName):
|
def load(fileName):
|
||||||
"""Loads an SVG image from a file."""
|
"""Loads an SVG image from a file."""
|
||||||
return load_stream(file(fileName))
|
return load_stream(open(fileName))
|
||||||
|
|
||||||
def load_stream(stream):
|
def load_stream(stream):
|
||||||
"""Loads an SVG image from a stream (can be a string or a file object)."""
|
"""Loads an SVG image from a stream (can be a string or a file object)."""
|
||||||
|
@ -16,6 +16,11 @@ except ImportError:
|
|||||||
raise ImportError('Can\'t find OpenCV Python module. If you\'ve built it from sources without installation, '
|
raise ImportError('Can\'t find OpenCV Python module. If you\'ve built it from sources without installation, '
|
||||||
'configure environment variable PYTHONPATH to "opencv_build_dir/lib" directory (with "python3" subdirectory if required)')
|
'configure environment variable PYTHONPATH to "opencv_build_dir/lib" directory (with "python3" subdirectory if required)')
|
||||||
|
|
||||||
|
try:
|
||||||
|
xrange # Python 2
|
||||||
|
except NameError:
|
||||||
|
xrange = range # Python 3
|
||||||
|
|
||||||
|
|
||||||
class DataFetch(object):
|
class DataFetch(object):
|
||||||
imgs_dir = ''
|
imgs_dir = ''
|
||||||
|
@ -6,10 +6,15 @@ import csv
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
|
try:
|
||||||
|
long # Python 2
|
||||||
|
except NameError:
|
||||||
|
long = int # Python 3
|
||||||
|
|
||||||
# trace.hpp
|
# trace.hpp
|
||||||
REGION_FLAG_IMPL_MASK = 15 << 16;
|
REGION_FLAG_IMPL_MASK = 15 << 16
|
||||||
REGION_FLAG_IMPL_IPP = 1 << 16;
|
REGION_FLAG_IMPL_IPP = 1 << 16
|
||||||
REGION_FLAG_IMPL_OPENCL = 2 << 16;
|
REGION_FLAG_IMPL_OPENCL = 2 << 16
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
|
@ -7,8 +7,6 @@ ones with missing __doc__ string.
|
|||||||
|
|
||||||
# Python 2/3 compatibility
|
# Python 2/3 compatibility
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
|
||||||
PY3 = sys.version_info[0] == 3
|
|
||||||
|
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
|
||||||
@ -17,11 +15,11 @@ if __name__ == '__main__':
|
|||||||
for fn in glob('*.py'):
|
for fn in glob('*.py'):
|
||||||
loc = {}
|
loc = {}
|
||||||
try:
|
try:
|
||||||
if PY3:
|
try:
|
||||||
exec(open(fn).read(), loc)
|
execfile(fn, loc) # Python 2
|
||||||
else:
|
except NameError:
|
||||||
execfile(fn, loc)
|
exec(open(fn).read(), loc) # Python 3
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if '__doc__' not in loc:
|
if '__doc__' not in loc:
|
||||||
print(fn)
|
print(fn)
|
||||||
|
@ -7,7 +7,6 @@ Sample-launcher application.
|
|||||||
# Python 2/3 compatibility
|
# Python 2/3 compatibility
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
PY3 = sys.version_info[0] == 3
|
|
||||||
|
|
||||||
# local modules
|
# local modules
|
||||||
from common import splitfn
|
from common import splitfn
|
||||||
@ -17,11 +16,11 @@ import webbrowser
|
|||||||
from glob import glob
|
from glob import glob
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
|
||||||
if PY3:
|
try:
|
||||||
import tkinter as tk
|
import tkinter as tk # Python 3
|
||||||
from tkinter.scrolledtext import ScrolledText
|
from tkinter.scrolledtext import ScrolledText
|
||||||
else:
|
except ImportError:
|
||||||
import Tkinter as tk
|
import Tkinter as tk # Python 2
|
||||||
from ScrolledText import ScrolledText
|
from ScrolledText import ScrolledText
|
||||||
|
|
||||||
|
|
||||||
@ -116,10 +115,10 @@ class App:
|
|||||||
name = self.demos_lb.get( self.demos_lb.curselection()[0] )
|
name = self.demos_lb.get( self.demos_lb.curselection()[0] )
|
||||||
fn = self.samples[name]
|
fn = self.samples[name]
|
||||||
loc = {}
|
loc = {}
|
||||||
if PY3:
|
try:
|
||||||
exec(open(fn).read(), loc)
|
execfile(fn, loc) # Python 2
|
||||||
else:
|
except NameError:
|
||||||
execfile(fn, loc)
|
exec(open(fn).read(), loc) # Python 3
|
||||||
descr = loc.get('__doc__', 'no-description')
|
descr = loc.get('__doc__', 'no-description')
|
||||||
|
|
||||||
self.linker.reset()
|
self.linker.reset()
|
||||||
|
@ -1,35 +1,36 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys
|
|
||||||
|
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
|
|
||||||
alpha = 0.5
|
alpha = 0.5
|
||||||
|
|
||||||
|
try:
|
||||||
|
raw_input # Python 2
|
||||||
|
except NameError:
|
||||||
|
raw_input = input # Python 3
|
||||||
|
|
||||||
print(''' Simple Linear Blender
|
print(''' Simple Linear Blender
|
||||||
-----------------------
|
-----------------------
|
||||||
* Enter alpha [0.0-1.0]: ''')
|
* Enter alpha [0.0-1.0]: ''')
|
||||||
if sys.version_info >= (3, 0): # If Python 3.x
|
input_alpha = float(raw_input().strip())
|
||||||
input_alpha = float(input())
|
|
||||||
else:
|
|
||||||
input_alpha = float(raw_input())
|
|
||||||
if 0 <= alpha <= 1:
|
if 0 <= alpha <= 1:
|
||||||
alpha = input_alpha
|
alpha = input_alpha
|
||||||
## [load]
|
# [load]
|
||||||
src1 = cv.imread('../../../../data/LinuxLogo.jpg')
|
src1 = cv.imread('../../../../data/LinuxLogo.jpg')
|
||||||
src2 = cv.imread('../../../../data/WindowsLogo.jpg')
|
src2 = cv.imread('../../../../data/WindowsLogo.jpg')
|
||||||
## [load]
|
# [load]
|
||||||
if src1 is None:
|
if src1 is None:
|
||||||
print ("Error loading src1")
|
print("Error loading src1")
|
||||||
exit(-1)
|
exit(-1)
|
||||||
elif src2 is None:
|
elif src2 is None:
|
||||||
print ("Error loading src2")
|
print("Error loading src2")
|
||||||
exit(-1)
|
exit(-1)
|
||||||
## [blend_images]
|
# [blend_images]
|
||||||
beta = (1.0 - alpha)
|
beta = (1.0 - alpha)
|
||||||
dst = cv.addWeighted(src1, alpha, src2, beta, 0.0)
|
dst = cv.addWeighted(src1, alpha, src2, beta, 0.0)
|
||||||
## [blend_images]
|
# [blend_images]
|
||||||
## [display]
|
# [display]
|
||||||
cv.imshow('dst', dst)
|
cv.imshow('dst', dst)
|
||||||
cv.waitKey(0)
|
cv.waitKey(0)
|
||||||
## [display]
|
# [display]
|
||||||
cv.destroyAllWindows()
|
cv.destroyAllWindows()
|
||||||
|
Loading…
Reference in New Issue
Block a user