Hola que tal? Estaba usando Python hace unos dias y no tenia problema, ayer que quise modificar mi codigo me salio un problema a la hora de compilar: UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 30: ordinal not in range(128)
Por lo que he leido dicen que es problema de acentos o eñes, en mi programa no hay nada de eso, ahora lo copio para que lo vean, necesito de su ayuda... estoy desesperada
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 13 17:41:56 2017
@author: pc
"""
# when ddepth=-1, the output image will have the same depth as the source
# cv2.CV_64F
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import matplotlib.patches as patches
import numpy as np
import cv2
from Class_2D_DoG import DoG_2D
from func_Custom import (Convert255ToBalanced, ConvertBalancedTo255)
import os
import sys
import scipy.io
#Ploting Settings
m=0.5
graph_size = (m*19.2, m*10.8)
graph_dpi = 300
if __name__ == "__main__":
#==============================================================================
# Setting the DoG Filter
#==============================================================================
#Set DoG Filter Parameters
Rc = 1.5
rR = 2.5
rV = 0.95
#Create Class: DoG Filter
DoG = DoG_2D(Rc=Rc, rR=rR, rV=rV)
#==============================================================================
# Setting First Derivative Filter
#==============================================================================
#First Derivate Filter: Horizontal and Veritical Directions
dx1 = np.array([[0,0,0],[-1.0,0,1.0],[0,0,0]])
dy1 = np.array([[0,0,0],[-1.0,0,1.0],[0,0,0]]).T
#==============================================================================
# Setting the Folder
#==============================================================================
#Set the folder
main_path = os.path.dirname(sys.argv[0])
pupil_name = 'p3'
img_name = 'Flores'
#Get file names from AD-
data_path_neg = os.path.join(main_path, pupil_name, img_name,'AD-')
AD_neg = os.listdir(data_path_neg)
AD_neg = AD_neg[0:13]
AD_neg = AD_neg[::-1]
#Get file names from AD+
data_path_pos = os.path.join(main_path, pupil_name, img_name, 'AD+')
AD_pos = os.listdir(data_path_pos)
AD_pos = AD_pos[0:13]
#==============================================================================
# Processing Loop
#==============================================================================
n = 25
AD = np.linspace(-3.0,+3.0, n)
Focus_DoG = np.zeros(n)
Focus_D1 = np.zeros(n)
for i in range(0,n):
if i < 12:
mat = scipy.io.loadmat(data_path_neg + '//' + AD_neg[i])
imgIn = mat['imag']
else:
mat = scipy.io.loadmat(data_path_pos + '//' + AD_pos[i-12])
imgIn = mat['imag']
#Convert input image from [0...128...255] to [-1...0...+1] (Optional)
# imgIn = Convert255ToBalanced(imgIn)
# imgIn = ConvertBalancedTo255(imgIn)
#Calculating: DoG Output
imgOut = cv2.filter2D(imgIn, cv2.CV_64F, DoG.Filter)
#Calculating: Focus Metric Based on DoG
[r,c] = imgIn.shape
Focus_DoG[i] = np.sum(np.sqrt(imgOut**2))/float(r*c)
#Calculating: First Derivative
Out_dx1 = cv2.filter2D(imgIn, cv2.CV_64F, dx1)
Out_dy1 = cv2.filter2D(imgIn, cv2.CV_64F, dy1)
#Calculating: Focus Metric Based on First Derivative
Focus_D1[i] = np.sum(np.sqrt(Out_dx1**2 + Out_dy1**2))/float(r*c)
#==============================================================================
# Correcting the Shift (Optional but recommended for "p3" data)
#==============================================================================
# if pupil_name == 'p3':
# AD = AD - 0.25
# AD = AD[2:]
# Focus_DoG = Focus_DoG[2:]
# Focus_D1 = Focus_D1[2:]
#==============================================================================
# Normalizing the Focus Metrics to the Maximum Value to make comparision.
#==============================================================================
Focus_DoG_norm = Focus_DoG/Focus_DoG.max()
Focus_D1_norm = Focus_D1/Focus_D1.max()
#==============================================================================
# Plotting
#==============================================================================
fig, ax = plt.subplots(2,1)
fig.set_size_inches(graph_size)
ax[0].plot(AD, Focus_D1_norm,'-or', label='1D')
ax[0].vlines(x=0, ymin=ax[0].axes.get_ylim()[0], ymax=ax[0].axes.get_ylim()[1], linestyle='--', color='k')
ax[0].hlines(y=1, xmin=ax[0].axes.get_xlim()[0], xmax=ax[0].axes.get_xlim()[1], linestyle='--', color='k')
ax[0].legend()
ax[1].plot(AD, Focus_DoG_norm,'-og', label='DoG')
ax[1].vlines(x=0, ymin=ax[1].axes.get_ylim()[0], ymax=ax[1].axes.get_ylim()[1], linestyle='--', color='k')
ax[1].hlines(y=1, xmin=ax[1].axes.get_xlim()[0], xmax=ax[1].axes.get_xlim()[1], linestyle='--', color='k')
ax[1].legend()
plt.show()
Class_2D_DoG
ofunc_Custom
. Recuerda que si especificas el encoding como UTF-8 (# -*- coding: utf-8 -*-
) debes guardar el script con esa codificación. Un saludo.