mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 07:13:02 +04:00
Define execfile, file, long, raw_input, xrange for Python 3
This commit is contained in:
@@ -7,8 +7,6 @@ ones with missing __doc__ string.
|
||||
|
||||
# Python 2/3 compatibility
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
from glob import glob
|
||||
|
||||
@@ -17,11 +15,11 @@ if __name__ == '__main__':
|
||||
for fn in glob('*.py'):
|
||||
loc = {}
|
||||
try:
|
||||
if PY3:
|
||||
exec(open(fn).read(), loc)
|
||||
else:
|
||||
execfile(fn, loc)
|
||||
except:
|
||||
try:
|
||||
execfile(fn, loc) # Python 2
|
||||
except NameError:
|
||||
exec(open(fn).read(), loc) # Python 3
|
||||
except Exception:
|
||||
pass
|
||||
if '__doc__' not in loc:
|
||||
print(fn)
|
||||
|
||||
@@ -7,7 +7,6 @@ Sample-launcher application.
|
||||
# Python 2/3 compatibility
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
# local modules
|
||||
from common import splitfn
|
||||
@@ -17,11 +16,11 @@ import webbrowser
|
||||
from glob import glob
|
||||
from subprocess import Popen
|
||||
|
||||
if PY3:
|
||||
import tkinter as tk
|
||||
try:
|
||||
import tkinter as tk # Python 3
|
||||
from tkinter.scrolledtext import ScrolledText
|
||||
else:
|
||||
import Tkinter as tk
|
||||
except ImportError:
|
||||
import Tkinter as tk # Python 2
|
||||
from ScrolledText import ScrolledText
|
||||
|
||||
|
||||
@@ -116,10 +115,10 @@ class App:
|
||||
name = self.demos_lb.get( self.demos_lb.curselection()[0] )
|
||||
fn = self.samples[name]
|
||||
loc = {}
|
||||
if PY3:
|
||||
exec(open(fn).read(), loc)
|
||||
else:
|
||||
execfile(fn, loc)
|
||||
try:
|
||||
execfile(fn, loc) # Python 2
|
||||
except NameError:
|
||||
exec(open(fn).read(), loc) # Python 3
|
||||
descr = loc.get('__doc__', 'no-description')
|
||||
|
||||
self.linker.reset()
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
|
||||
import cv2 as cv
|
||||
|
||||
alpha = 0.5
|
||||
|
||||
try:
|
||||
raw_input # Python 2
|
||||
except NameError:
|
||||
raw_input = input # Python 3
|
||||
|
||||
print(''' Simple Linear Blender
|
||||
-----------------------
|
||||
* Enter alpha [0.0-1.0]: ''')
|
||||
if sys.version_info >= (3, 0): # If Python 3.x
|
||||
input_alpha = float(input())
|
||||
else:
|
||||
input_alpha = float(raw_input())
|
||||
input_alpha = float(raw_input().strip())
|
||||
if 0 <= alpha <= 1:
|
||||
alpha = input_alpha
|
||||
## [load]
|
||||
# [load]
|
||||
src1 = cv.imread('../../../../data/LinuxLogo.jpg')
|
||||
src2 = cv.imread('../../../../data/WindowsLogo.jpg')
|
||||
## [load]
|
||||
# [load]
|
||||
if src1 is None:
|
||||
print ("Error loading src1")
|
||||
print("Error loading src1")
|
||||
exit(-1)
|
||||
elif src2 is None:
|
||||
print ("Error loading src2")
|
||||
print("Error loading src2")
|
||||
exit(-1)
|
||||
## [blend_images]
|
||||
# [blend_images]
|
||||
beta = (1.0 - alpha)
|
||||
dst = cv.addWeighted(src1, alpha, src2, beta, 0.0)
|
||||
## [blend_images]
|
||||
## [display]
|
||||
# [blend_images]
|
||||
# [display]
|
||||
cv.imshow('dst', dst)
|
||||
cv.waitKey(0)
|
||||
## [display]
|
||||
# [display]
|
||||
cv.destroyAllWindows()
|
||||
|
||||
Reference in New Issue
Block a user