<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>画像検出 | N-mode</title>
	<atom:link href="https://neconini.com/archives/tag/%e7%94%bb%e5%83%8f%e6%a4%9c%e5%87%ba/feed" rel="self" type="application/rss+xml" />
	<link>https://neconini.com</link>
	<description>気になったことは全部やってみよ♪</description>
	<lastBuildDate>Thu, 20 Jul 2023 02:12:55 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://neconini.com/wp-content/uploads/2022/04/cropped-logo-1-32x32.png</url>
	<title>画像検出 | N-mode</title>
	<link>https://neconini.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/>
<atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/>
<atom:link rel="hub" href="https://websubhub.com/hub"/>
<atom:link rel="self" href="https://neconini.com/archives/tag/%e7%94%bb%e5%83%8f%e6%a4%9c%e5%87%ba/feed"/>
	<item>
		<title>工場などで使える画像診断装置を自作してみよう！　その3</title>
		<link>https://neconini.com/archives/272</link>
					<comments>https://neconini.com/archives/272#respond</comments>
		
		<dc:creator><![CDATA[Makoto]]></dc:creator>
		<pubDate>Tue, 07 Mar 2023 06:52:26 +0000</pubDate>
				<category><![CDATA[RaspberryPi]]></category>
		<category><![CDATA[プログラム]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[画像検出]]></category>
		<guid isPermaLink="false">https://neconini.com/?p=272</guid>

					<description><![CDATA[ジェームズ それではプログラムを書いていきましょう。 前提条件ですが、宛先が西営業所か東営業所で間違えて ラインに流れていないかのチェックプログラムとなります。 Makoto はーい！ ジェームズ これでほぼリアルタイム [&#8230;]]]></description>
										<content:encoded><![CDATA[<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img fetchpriority="high" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>それではプログラムを書いていきましょう。</p>
<p>前提条件ですが、宛先が西営業所か東営業所で間違えて</p>
<p>ラインに流れていないかのチェックプログラムとなります。</p>
</div>
</div>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>はーい！</p>
</div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img fetchpriority="high" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>これでほぼリアルタイムの検出ができると思います。</p>
</div>
</div>
<pre># ライブラリ設定
import cv2                       # OpenCV
import numpy as np               # OpenCV オプション
import subprocess                # 音楽再生ライブラリ
from datetime import datetime    # 日付ライブラリ

# OpenCV設定
cap = cv2.VideoCapture(0)    # 
cap.set(cv2.CAP_PROP_FPS, 5) # FPS設定 ラズパイ4の4GBでは5が上限かもしれません
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 300) # 小さいほど処理は早くなります

# 検査画像1設定
nishi = cv2.imread('Nishi.png')
nishi_gray = cv2.cvtColor(nishi, cv2.COLOR_BGR2GRAY)

# 検査画像2設定
higashi = cv2.imread('Higashi.png')
higashi_gray = cv2.cvtColor(higashi, cv2.COLOR_BGR2GRAY)

#Pass/Ng設定
Pass = nishi_gray
Ng = higashi_gray

# テンプレートマッチング画像の高さ、幅を取得する
h, w = nishi_gray.shape

#初期値設定
threshold = 0.8          # テンプレート検索の同一性割合
search_flg = False       # 成否判定フラグ
read_count_flg = 0       # 成否判定初回限定フラグ
sound = 0                # 成否判定音源フラグ

#ファイル名設定関数
def filename(trg):
    # 日付取得
    date = datetime.now().strftime("%Y%m%d_%H%M%S")
    # 画像保存名
    if  trg == 1:
        fname = 'Pass/' + date + 'image.png'
    else:
        fname = 'Ng/' + date + 'image.png'
        
    return  fname

#プログラム開始 このループが処理時間の主要な部分
while True:
    #キャプチャ取得
    ret, img = cap.read()
    if not ret:
        break

    # グレースケール化
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

##########Pass##########
    # 処理対象画像に対して、テンプレート画像との類似度を算出する
    res = cv2.matchTemplate(img_gray, Pass, cv2.TM_CCOEFF_NORMED)

    # 類似度の高い部分を検出する
    loc = np.where(res &gt;= threshold)

    # 検出した部分に赤枠をつける
    for pt in zip(*loc[::-1]):
        cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
        #テンプレート確認時文字入れ
        cv2.putText(img, "Pass", (10, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 8)
        search_flg = True
        if read_count_flg == 0:
            sound = 1
            read_count_flg += 1
            cv2.imwrite(filename(1), img)

###########Ng###########
    # 処理対象画像に対して、テンプレート画像との類似度を算出する
    res = cv2.matchTemplate(img_gray, Ng, cv2.TM_CCOEFF_NORMED)

    # 類似度の高い部分を検出する
    loc = np.where(res &gt;= threshold)

    # 検出した部分に赤枠をつける
    for pt in zip(*loc[::-1]):
        cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
        #テンプレート確認時文字入れ
        cv2.putText(img, "NG", (10, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 8)
        search_flg = True
        if read_count_flg == 0:
            sound = 2
            read_count_flg += 1
            cv2.imwrite(filename(2), img)

    # 未検出時文字入れ
    if not search_flg:         
        cv2.putText(img, "Scanning...", (10, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 8)
        read_count_flg = 0

    # 検出フラグリセット
    search_flg = False

    # 画像の表示
    cv2.imshow('Frame', img)

    # 音源設定
    if sound == 1:
        subprocess.Popen(['aplay', 'OK.mp3])
    if sound == 2:
        subprocess.Popen(['aplay', 'NG.mp3])
    sound = 0

    #終了キー（なにかキーが押されたら終了）
    key = cv2.waitKey(1)
    if key != -1:
        break

cap.release()
cv2.destroyAllWindows()

</pre>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>できたぁー！</p>
<p>これで上司さんに怒られなくて済むよ！</p>
</div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img fetchpriority="high" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>それは良かったですね</p>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://neconini.com/archives/272/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>工場などで使える画像診断装置を自作してみよう！　その２</title>
		<link>https://neconini.com/archives/266</link>
					<comments>https://neconini.com/archives/266#respond</comments>
		
		<dc:creator><![CDATA[Makoto]]></dc:creator>
		<pubDate>Wed, 01 Mar 2023 23:17:36 +0000</pubDate>
				<category><![CDATA[RaspberryPi]]></category>
		<category><![CDATA[プログラム]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[画像検出]]></category>
		<guid isPermaLink="false">https://neconini.com/?p=266</guid>

					<description><![CDATA[ジェームズ 続きをやっていきましょう。 プログラムを書く前に、前提条件のライブラリを インストールしておきましょう。 まずはOPENCVのインストールをしましょう。 sudo pip3 install opencv-py [&#8230;]]]></description>
										<content:encoded><![CDATA[<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>続きをやっていきましょう。<br />
プログラムを書く前に、前提条件のライブラリを</p>
<p>インストールしておきましょう。<br />
まずはOPENCVのインストールをしましょう。</p>
</div>
</div>
<pre>sudo pip3 install opencv-python
</pre>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>次にNumPyを更新しましょう。</p>
</div>
</div>
<pre>sudo pip3 install numpy --upgrade
</pre>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person"> </div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>これで次回作っていくプログラムを動かす準備は完了です。</p>
</div>
</div>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>はーい！</p>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://neconini.com/archives/266/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>工場などで使える画像診断装置を自作してみよう！　その１</title>
		<link>https://neconini.com/archives/263</link>
					<comments>https://neconini.com/archives/263#respond</comments>
		
		<dc:creator><![CDATA[Makoto]]></dc:creator>
		<pubDate>Tue, 28 Feb 2023 13:08:59 +0000</pubDate>
				<category><![CDATA[RaspberryPi]]></category>
		<category><![CDATA[プログラム]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[画像検出]]></category>
		<guid isPermaLink="false">https://neconini.com/?p=263</guid>

					<description><![CDATA[Makoto うーん ジェームズ どうされました？ Makoto 上司さんから安く画像判別装置を作って欲しいという依頼があったのー ジェームズ ほうほう Makoto ラズパイでなんとか出来ないかなーって考えてるんだけど [&#8230;]]]></description>
										<content:encoded><![CDATA[<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>うーん</p>
</div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>どうされました？</p>
</div>
</div>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>上司さんから安く画像判別装置を作って欲しいという依頼があったのー</p>
</div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>ほうほう</p>
</div>
</div>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>ラズパイでなんとか出来ないかなーって考えてるんだけど何がいいのかなあ。。。</p>
</div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>それでしたらOpenCVをお勧めいたします<br />
一度作ってみましょうか</p>
</div>
</div>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>わーい！</p>
</div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>まず、前提条件ですが<br />
画像処理の場合は処理能力が必要なので<br />
RaspberryPi4の４Gぐらいは最低欲しいところです<br />
また、画像処理ですのでカメラとカメラを定点で固定するための装置も必要ですね</p>
</div>
</div>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>ふむふむ</p>
</div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>安ければ２万円以内で組めるかと思います</p>
</div>
</div>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>結構リーズナブル！</p>
</div>
</div>
<div class="speech-wrap sb-id-12 sbs-stn sbp-l sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/Cat1.webp" alt="ジェームズ" width="500" height="500" /></figure>
<div class="speech-name">ジェームズ</div>
</div>
<div class="speech-balloon">
<p>まずはアイテム揃えてから準備をしてプログラムを書いていきましょうか</p>
</div>
</div>
<div class="speech-wrap sb-id-15 sbs-stn sbp-r sbis-cb cf">
<div class="speech-person">
<figure class="speech-icon"><img loading="lazy" decoding="async" class="speech-icon-image" src="https://neconini.com/wp-content/uploads/2022/04/me.jpeg" alt="Makoto" width="96" height="96" /></figure>
<div class="speech-name">Makoto</div>
</div>
<div class="speech-balloon">
<p>はーい</p>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://neconini.com/archives/263/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Disk: Enhanced  を使用したページ キャッシュ
遅延読み込み (feed)
Disk を使用して縮小 
データベースキャッシュ 2/5 クエリーが0.002秒で Disk を使用中

Served from: neconini.com @ 2026-04-28 23:59:34 by W3 Total Cache
-->