質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Flask

FlaskはPython用のマイクロフレームワークであり、Werkzeug・Jinja 2・good intentionsをベースにしています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

984閲覧

Flaskで作ったものをHerokuにデプロイするとapplication errorが出る.

退会済みユーザー

退会済みユーザー

総合スコア0

Flask

FlaskはPython用のマイクロフレームワークであり、Werkzeug・Jinja 2・good intentionsをベースにしています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/04/26 00:10

編集2020/04/26 00:27

モザイクアートを作成するプログラムを作り、ローカル環境ではうまく動作したのですが、
herokuにデプロイし、heroku open すると application errorが出てしまいました.
ログを見ると、

heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-savannah-92123.herokuapp.com request_id=daad2ca8-69e8-4952-a975-5375f82681b9 fwd="180.146.24.157" dyno= connect= service= status=503 bytes= protocol=https

とありました.
herokuの再起動などしましたが、解決しませんでした.

(追記)
ログをちゃんと見ると
import cv2
にImportErrorが出ていました.requirementsに
opencv-python==4.2.0.32
と書いてあるんですが違うのでしょうか.

Python

1#app.py 2from flask import Flask, render_template, request 3from PIL import Image,ImageFilter 4import subprocess 5import os 6import random 7import math 8import time 9import numpy as np 10import glob 11import cv2 12 13app = Flask(__name__) 14 15# getのときの処理 16@app.route('/', methods=['GET']) 17def get(): 18 return render_template('index.html', \ 19 title = 'モザイクアートを作ろう', \ 20 message = '設定してください') 21 22# postのときの処理 23@app.route('/', methods=['POST']) 24def post(): 25 SourceDir = request.form['source'] 26 GoalImage = request.form["goal"] 27 OutputImage="output.jpg" 28 SourceImageSize=(60,40) 29 30 TargetZoom=11 31 32 used_count = 3 33 34 35 def __create_tile(org_image,height,width): 36 37 w, h = org_image.size 38 RectList=[] 39 for y in range(0, math.floor(h / height) + 1): 40 for x in range(0, math.floor(w / width) + 1): 41 height2 = y * height 42 width2 = x * width 43 crap_img = org_image.crop((width2, height2, width2 + width, height2 + height)) 44 RectList.append((crap_img,width2,height2)) 45 return RectList 46 47 def __clac_hist(img): 48 49 hist_list = [] 50 color = ['r','g','b'] 51 images = np.asarray(img) 52 53 for i in enumerate(color): 54 hist_list.append(cv2.calcHist([images],[i[0]],None,[256],[0,256])) 55 return hist_list 56 57 if __name__=="__main__": 58 59 startTime=time.time() 60 61 62 target=Image.open(GoalImage) 63 target=target.resize(tuple(math.floor(i*TargetZoom) for i in target.size)) 64 65 66 print("%s:タイルリストを生成開始"%(str(time.time()-startTime))) 67 tiles = __create_tile(target,SourceImageSize[1],SourceImageSize[0]) 68 print("%s:タイルリストを生成完了"%(str(time.time()-startTime))) 69 70 file_paths = glob.glob(SourceDir+"\*") 71 src_hist_dict = {} 72 print("%s:全素材画像ヒストグラムを計算開始"%(str(time.time()-startTime))) 73 for file_path in file_paths: 74 file_name = file_path.split("\")[-1] 75 76 try: 77 src_image = Image.open(file_path).resize(SourceImageSize) 78 except Exception: 79 continue 80 src_hist_dict[file_name] = [src_image,__clac_hist(src_image),0] 81 print("%s:全素材画像ヒストグラムを計算完了"%(str(time.time()-startTime))) 82 83 84 Target=Image.new("RGB",target.size,255) 85 86 print("%s:モザイクアート生成開始"%(str(time.time()-startTime))) 87 while(len(tiles) > 0): 88 result = [] 89 90 print("残りタイル:" + str(len(tiles))) 91 r=random.randrange(len(tiles)) 92 tileRect=tiles[r] 93 del tiles[r] 94 95 tile_hist = __clac_hist(tileRect[0]) 96 97 tile_hist = np.array(tile_hist) 98 tile_hist = tile_hist.reshape(tile_hist.shape[0] * tile_hist.shape[1], 1) 99 100 101 for file_name,src_hist in src_hist_dict.items(): 102 src_hist = np.array(src_hist[1]) 103 src_hist = src_hist.reshape(src_hist.shape[0] * src_hist.shape[1], 1) 104 105 d = cv2.compareHist(tile_hist, src_hist, cv2.HISTCMP_INTERSECT) 106 result.append([d,file_name]) 107 result.sort(reverse=True) 108 109 Target.paste(src_hist_dict[result[0][1]][0],(tileRect[1],tileRect[2])) 110 111 src_hist_dict[result[0][1]][2] = src_hist_dict[result[0][1]][2] + 1 112 113 114 115 print("%s:モザイクアート生成完了"%(str(time.time()-startTime))) 116 print("処理が完了するまでしばらくお待ち下さい") 117 Target.save(OutputImage) 118 Target.show() 119 return render_template("index.html",message="モザイクアート生成完了") 120 121 122if __name__=="__main__": 123 app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000))) 124

index.html

1<!DOCTYPE html> 2<html lang="jn" dir="ltr"> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 <h1>{{ title }}</h1> 9<p>{{ message }}</p> 10<form action="/" method="POST" enctype="multipart/form-data"> 11 <div> 12 <label for="name">素材の入ったフォルダ:</label> 13 <input type="text" id="source" name="source" placeholder="C:xxxx"> 14 </div> 15 <div> 16 <label for="name">目標画像:</label> 17 <input type="text" id="goal" name="goal" placeholder="C:xxxx"> 18 </div> 19 <div> 20 <input type="submit" value="モザイクアート生成"> 21 </div> 22 <div> 23</form> 24 </body> 25</html>

Plocfile

1web: gunicorn -b :$PORT app:app

requirements.txt

1Flask==1.1.1 2glob2==0.7 3gunicorn==20.0.4 4Jinja2==2.10.1 5numpy==1.18.1 6opencv-python==4.2.0.32 7Pillow==5.1.0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

どうやらそのままではherokuでopencvは使えないようでした.
以下サイトを参照し、うまくいきました.

https://qiita.com/maeda_mikio/items/1a6899e104aac7b138fc

投稿2020/04/26 01:07

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

どうやらそのままではherokuでopencvは使えないようでした.
以下サイトを参照し、うまくいきました.

https://qiita.com/maeda_mikio/items/1a6899e104aac7b138fc

投稿2020/04/26 00:59

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問