336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import time
import cv2
import numpy as np
from mss import mss


print("load finger png files...")
imageFinger1 = cv2.imread("finger1.png")
imageFinger2 = cv2.imread("finger2.png")
imageFinger3 = cv2.imread("finger3.png")
imageFinger4 = cv2.imread("finger4.png")
print("load finger png files... Done")


with mss() as sct:
mon1 = sct.monitors[1]
mon2 = sct.monitors[2]
mon3 = sct.monitors[3]
mon4 = sct.monitors[4]
box = {'top': mon4['top'] +400, 'left': mon4['left'] + 200, 'width': 150, 'height': 190}
# mon = sct.monitors[0]
while True:
last_time = time.time()
capturedImage = np.array(sct.grab(box))
capturedImage = cv2.cvtColor(capturedImage, cv2.COLOR_BGRA2RGB)
imageFinger1 = cv2.cvtColor(imageFinger1, cv2.COLOR_BGRA2RGB)
imageFinger2 = cv2.cvtColor(imageFinger2, cv2.COLOR_BGRA2RGB)

#print('fps: {0}'.format(1 / (time.time()-last_time)))

#cv2.imshow('capturedImage', capturedImage)

difference = cv2.subtract(capturedImage, imageFinger1)
b, g, r = cv2.split(difference)
diff = cv2.countNonZero(b) + cv2.countNonZero(g) + cv2.countNonZero(r)
cv2.imshow('imageFinger1', difference)
print("png 1 diff = " + str(diff))
if diff == 0:
print("Detected finger png 1 !!!")
cv2.imshow('imageFinger1', difference )

difference = cv2.subtract(capturedImage, imageFinger2)
b, g, r = cv2.split(difference)
diff = cv2.countNonZero(b) + cv2.countNonZero(g) + cv2.countNonZero(r)
print("png b bbbb = " + str(b))
print("png b diff = " + str(cv2.countNonZero(b)))
print("png g diff = " + str(cv2.countNonZero(g)))
print("png r diff = " + str(cv2.countNonZero(r)))
cv2.imshow('imageFinger2', difference)
print("png 2 diff = " + str(diff))

if diff == 0:
print("Detected finger png 2 !!!")
cv2.imshow('imageFinger1', difference)


if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break




'Programming > Python' 카테고리의 다른 글

[Python/OpenCV] Near-Duplicate Image Detection #2  (0) 2020.06.02
[Python] List 정렬 프로그램 구현  (0) 2017.02.06
[Python 3.6] * 찍기  (0) 2017.02.02

Audio Wave Form Renderer

Programming/C# 2018. 10. 24. 15:13 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Audio Wave Form Renderer




Test Harness App


Test Harness UI


Example Waveforms


Basic solid colour waveform Basic solid color

Gradient vertical bars (old SoundCloud style) Gradient vertical bars

Blocks (SoundCloud style) Blocks

Orange Blocks

Transparent Backgrounds Transparent Background

Transparent Background

You can check out all the source code on GitHub





https://markheath.net/post/naudio-png-waveform-rendering

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Java SocketServer control Image, DBConnect, String




package com.tistory.tansanc;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import javax.imageio.ImageIO;

class DBConnect {
	ResultSet rs = null;
	Connection conn = null;
	Statement stmt = null;
	public DBConnect() {
		try {
			String url = "jdbc:sqlserver://192.168.10.17:1433;DatabaseName=MSSQLSERVER";
			
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn = DriverManager.getConnection(url, "sa", "1234");
			stmt = conn.createStatement();
			

		} catch (Exception e) {

		}
	}

	public void finalize() {
		try {
			rs.close();
			stmt.close();
			conn.close();
		} catch (Exception e) {

		}
	}
}

class PerClientThread extends Thread {
	Socket s;
	static ArrayList socketArray = new ArrayList();
	static DBConnect dbc;
	
	public PerClientThread()
	{
		
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub

		socketArray.add(s);
		BufferedReader br;

		
		try {
			br = new BufferedReader(new InputStreamReader(s.getInputStream()));
			String temp;
			while ((temp = br.readLine()) != null) {
				// DB Query
				if (temp.startsWith("select")) {
					
					try {
						dbc.rs = dbc.stmt.executeQuery("SELECT * FROM [dbo].[TESTDB]");

						while (dbc.rs.next()) {
							String field1 = dbc.rs.getString("Date");
							String field2 = dbc.rs.getString("FileName");
							System.out.println(field1);
							System.out.println(field2);

							java.sql.Blob blb = dbc.rs.getBlob("Image");
							byte[] imagebytes = blb.getBytes(0, (int) blb.length());
							BufferedImage theImage = ImageIO.read(new ByteArrayInputStream(imagebytes));

						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					temp = "SQL:" + temp;
					System.out.println(temp);
				}
				// Arduino
				else if (temp.startsWith("insert"))
				{
					
				}
				// Arduino
				else if (temp.startsWith("image"))
				{

			        int size = Integer.parseInt(br.readLine());
			        
			        DataInputStream inputStream = new DataInputStream(s.getInputStream());
			        
			        byte[] imageAr = new byte[size];
			        inputStream.read(imageAr, 0, size);

			        BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageAr));

			        System.out.println("Received " + image.getHeight() + "x" + image.getWidth() + ": " + System.currentTimeMillis());
			        ImageIO.write(image, "png", new File("C:\\test2.png"));


				}
				// Arduino
				else if (temp.startsWith("to"))
				{
					
				}
				System.out.print(s.getInetAddress() + " : ");
				System.out.println(temp);
				for (int i = 0; i < socketArray.size(); i++) {
					PrintWriter os = new PrintWriter(socketArray.get(i).getOutputStream(), true);
					os.print(s.getInetAddress() + " : ");
					os.println(temp);
				}
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		super.run();
	}
}

public class Server {
	public static void main(String[] args) throws Exception {
 
		System.out.println("Server Side");
		ServerSocket ss = new ServerSocket(33333);
		Socket s;
		while (true) {
			s = ss.accept();
			PerClientThread pct = new PerClientThread();
			pct.s = s;
			pct.dbc = new DBConnect();
			pct.start();
		}

	}
}










Client.java
package com.tistory.tansanc;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;

class MyFrame extends JFrame {
	public static JTextArea textArea;
	JTextField textField;
	PrintWriter out;
	Socket s;

	public MyFrame() {
		textArea = new JTextArea();
		textField = new JTextField();
		add(BorderLayout.CENTER, textArea);
		add(BorderLayout.SOUTH, textField);
		textField.addActionListener(new FieldListener());
		setSize(300, 200);
		setTitle("채팅프로그램 Client");
		setVisible(true);
		// GUI를 설계한다.
	}

	class FieldListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if (textField.getText().compareTo("image") == 0) {

				BufferedImage image;
				ByteArrayOutputStream byteArrayOutputStream = null;
				DataOutputStream os = null;
				try {
					image = ImageIO.read(new File("C:\\test.png"));
					byteArrayOutputStream = new ByteArrayOutputStream();
					ImageIO.write(image, "png", byteArrayOutputStream);
					os = new DataOutputStream(s.getOutputStream());
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				try {
					int size = byteArrayOutputStream.size();
					out.println("image");
					out.println(size);
					os.write(byteArrayOutputStream.toByteArray());
					os.flush();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

			} else {
				out.println(textField.getText());
				textField.setText("");
			}
			// 메세지 보내기
		}
	}
}

class SendThread extends Thread {
	PrintWriter out;

	public SendThread(PrintWriter out) {
		this.out = out;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		super.run();
	}
}

class RecvThread extends Thread {
	BufferedReader in;

	public RecvThread(BufferedReader in) {
		this.in = in;
	}

	@Override
	public void run() {
		String temp;
		try {
			while ((temp = in.readLine()) != null) {

				MyFrame.textArea.setText(MyFrame.textArea.getText() + "\n" + temp);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

class ClientModule {
	MyFrame mFrame;
	SendThread mSendThread;
	RecvThread mRecvThread;
	Socket s;

	// 서버에 패킷을 보내는 Thread
	// 서버로부터 패킷을 받는 Thread
	public ClientModule() // 준비
	{

		try {
			s = new Socket("192.168.10.17", 33333);
			PrintWriter out = new PrintWriter(s.getOutputStream(), true);
			BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
			mFrame = new MyFrame(); // GUI 객체
			mFrame.s = s;
			mFrame.out = out;
			mSendThread = new SendThread(out);
			mRecvThread = new RecvThread(in);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	void start() // 시작
	{
		mSendThread.start();
		mRecvThread.start();
	}
}

public class Client {
	public static void main(String[] args) {
		ClientModule cm = new ClientModule();
		// 초기화 작업
		cm.start();
		// Thread.start();
	}
}





MFC Bitmap Button

Programming/MFC 2016. 10. 18. 13:22 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MFC Bitmap Button



BitmapButton

ImageButton



1. Button Property


[Owner Draw] : True










2. Add Member Variable









3. Change Member Variable Type



CButton -> CBitmapButton








4. Load Bitmaps









m_Connect_Btn.LoadBitmaps(IDB_BITMAP_CONNECT_RESOURCE, IDB_BITMAP_CONNECT_SEL, IDB_BITMAP_CONNECT_FOCUS, IDB_BITMAP_CONNECT_DISABLED)
m_Connect_Btn.SizeToContent();








336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

카메라 인텐트로 띄운후 해당 이미지 ImageView에 띄우기


1. 카메라 인텐트 띄우기


Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);


2. 갤러리 인텐트 띄우기



Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 2);

인텐트 후 Image 불러오기




	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		if (resultCode == RESULT_OK)
		{
			if (requestCode == 1) // 1 은 위에서 startActivityForResult(intent, 1);
			{
				ImageView imageView1 = (ImageView)findViewById(R.id.imageView1);
				Bitmap bm = (Bitmap) data.getExtras().get("data");
				imageView1.setImageBitmap(bm);
			}
		}
	}

'Programming > Android' 카테고리의 다른 글

Android SQLite Select Where And &  (0) 2013.05.17
안드로이드 BItmap ImageView Drawable  (0) 2013.05.16
Intent 정리  (0) 2013.05.09
파일 이름 일괄 변경 DarkNamer  (0) 2013.05.05
MyLocation Class  (0) 2013.05.04