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

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

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Python

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

Q&A

3回答

7884閲覧

pythonコードをC#に変換

hoge2021

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Python

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

0グッド

0クリップ

投稿2021/12/22 05:29

編集2022/01/12 10:55

前提・実現したいこと

pythonコードをC#に変換したいです。
学習のためです。
いろいろ試してみましたが自分の知識不足のため実装できていません。
すみませんがお願いいたします。

該当のソースコード

ソースコード import face_recognition import cv2 import numpy as np # This is a demo of running face recognition on live video from your webcam. It's a little more complicated than the # other example, but it includes some basic performance tweaks to make things run a lot faster: # 1. Process each video frame at 1/4 resolution (though still display it at full resolution) # 2. Only detect faces in every other frame of video. # PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam. # OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this # specific demo. If you have trouble installing it, try any of the other demos that don't require it instead. # Get a reference to webcam #0 (the default one) video_capture = cv2.VideoCapture(0) # Load a sample picture and learn how to recognize it. Ryo_image = face_recognition.load_image_file("image/Ryo2.jpeg") Ryo_face_encoding = face_recognition.face_encodings(Ryo_image)[0] Hayate_image = face_recognition.load_image_file("image/Hayate.jpg") Hayate_face_encoding = face_recognition.face_encodings(Hayate_image)[0] # Load a second sample picture and learn how to recognize it. Nisioka_image = face_recognition.load_image_file("image/nisioka.jpg") Nisioka_face_encoding = face_recognition.face_encodings(Nisioka_image)[0] # Create arrays of known face encodings and their names known_face_encodings = [ Ryo_face_encoding, Hayate_face_encoding, Nisioka_face_encoding ] known_face_names = [ "Yamamoto Ryo", "Kinosita Hayate", "nishioka hage" ] # Initialize some variables face_locations = [] face_encodings = [] face_names = [] process_this_frame = True while True: # Grab a single frame of video ret, frame = video_capture.read() # Resize frame of video to 1/4 size for faster face recognition processing small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) rgb_small_frame = small_frame[:, :, ::-1] # Only process every other frame of video to save time if process_this_frame: # Find all the faces and face encodings in the current frame of video face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) face_names = [] for face_encoding in face_encodings: # See if the face is a match for the known face(s) matches = face_recognition.compare_faces(known_face_encodings, face_encoding) name = "Unknown" # # If a match was found in known_face_encodings, just use the first one. # if True in matches: # first_match_index = matches.index(True) # name = known_face_names[first_match_index] # Or instead, use the known face with the smallest distance to the new face face_distances = face_recognition.face_distance(known_face_encodings, face_encoding) best_match_index = np.argmin(face_distances) if matches[best_match_index]: name = known_face_names[best_match_index] face_names.append(name) process_this_frame = not process_this_frame # Display the results for (top, right, bottom, left), name in zip(face_locations, face_names): # Scale back up face locations since the frame we detected in was scaled to 1/4 size top *= 4 right *= 4 bottom *= 4 left *= 4 # Draw a box around the face cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) # Draw a label with a name below the face cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED) font = cv2.FONT_HERSHEY_DUPLEX cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1) # Display the resulting image cv2.imshow('Video', frame) # Hit 'q' on the keyboard to quit! if cv2.waitKey(1) & 0xFF == ord('q'): break # Release handle to the webcam video_capture.release() cv2.destroyAllWindows()

補足情報(FW/ツールのバージョンなど)

python3.7.3

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

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

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

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

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

meg_

2021/12/22 06:01

> 学習のためです。 いろいろ試してみましたが自分の知識不足のため実装できていません。 自学習であれば時間をかけて少しずつ知識を付けるしかないと思います。時間をかけられない理由でもあるのでしょうか?
退会済みユーザー

退会済みユーザー

2021/12/22 06:05

学習のためなら、それこそ自分で勉強しながら少しづつ書いてみればいいのでは。
guest

回答3

0

Convert Python to C#がオンラインで変換してくれるようです。
また、pytocsという変換ツールもあります。

こういう変換がどれぐらいうまくいくのかは興味のあるところです。
是非試してみて、結果を報告してください。

投稿2021/12/22 09:02

ppaul

総合スコア24666

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

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

0

○○のコードを●●に変換

ってたまに質問として出るんですけど、多くは質問ではなく作業依頼に近しい内容にでしかなく、
本当にやろうと思ったら双方の言語をきちんと使いこなせないとできないわけです。
それでもと言うのでしたら

  • ○○しかできないなら●●を基礎からしっかり覚えてやるしかなく
  • ●●しかできないなら○○を基礎から覚えて読み解けるようになるか、○○のコードにも要件や仕様があるわけでその要件や仕様を元に同じインプットで同じアウトプットとなるようなコードを1から書くことになると思います
  • どっちもできないなら両方覚えるか、●●を覚えて↑の後者で対応

まあ探せば「○○のコードを●●に変換してくれるツール」はあるでしょうけど、同じ要件で同じ言語でも人によって書くコードは同じにはならないわけで、精度は保証されないので、やはり挙げた3点のいずれかです。

投稿2021/12/22 07:49

編集2021/12/22 07:51
m.ts10806

総合スコア80765

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

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

0

残念ながら、ここではコード作成依頼は受け付けておりません。

まずはあなたなりにコードを書いてみましょう。
そのうえで、わからないことがあればそのコードとともに聞いていただければお答えできるかと思います

投稿2021/12/22 06:08

y_waiwai

総合スコア87719

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問