我正在尝试运行此代码。但它不起作用。想法是访问带有images'url的文件,访问这些图像,调整大小和保存图像。我使用的是Python 3.4,opencv 3.0和Visual Studio。欢迎任何帮助。
angular.module('app3', []).service('sharedService', function () {
this.Country = 'USA';
this.scope = null;
this. observerCallbacks = [];
//register an observer
this.registerObserverCallback = function (callback) {
this.observerCallbacks.push(callback);
};
//call this when you know 'foo' has been changed
this.notifyObservers = function () {
alert('notifed');
angular.forEach(this.observerCallbacks, function (callback) {
console.log('notification');
callback();
});
};
})
angular.module('app2', ['app3']).controller('app2Controller', function ($scope, $rootScope, sharedService) {
console.log('Controller 2 loaded');
var updateCountry = function () {
$scope.MyCountry = sharedService.Country;
};
sharedService.registerObserverCallback(updateCountry);
console.log(sharedService);
// this needs lazy loading
// $rootScope = sharedService.scope;
// console.log(sharedService.Country);
// $scope.MyCountry = sharedService.Country;
})
angular.module('app1',['app1','app3']).controller('app1Controller',function($scope,$rootScope,sharedService)
{
$scope.Countries = ['Egypt', 'KSA'];
$scope.Country = '';
sharedService.scope = $rootScope;
$scope.DrpChange = function () {
//$stateParams.Country = $scope.Country;
//$state.current.params.Country = $scope.Country;
//console.log($state.current.params.Country);
console.log(sharedService);
sharedService.Country = $scope.Country;
sharedService.notifyObservers();
// this is not working because the rootscope is not shared
$rootScope.$emit("Country.changed", $scope.Country);
}
})
angular.bootstrap(document.getElementById("app2"), ['app2']);
答案 0 :(得分:0)
添加
store_raw_images()
到文件的末尾,以便在VS中运行时执行该函数。
这解决了您的问题,但不是很好的风格,因为无论何时导入模块都会执行该功能 - 通常您希望更好地控制代码执行的时间。
要将其转换为可以从命令行运行的脚本,请添加
if __name__ == '__main__':
store_raw_images()
如果您从命令行调用脚本,这将执行该功能,但如果您将模块导入另一个模块或脚本,则在您使用store_raw_images()
}调用该函数之前,该功能将无法执行p>