Created
March 7, 2020 14:05
-
-
Save Jragon/8caa887f0f40fad57ff0ddc2018a978b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import math | |
import numpy as np | |
from PIL import Image | |
import itertools | |
center1 = [450, 204] | |
start1 = [402, 156] | |
data1 = [156, 147, 122, 157, 148, 123, 157, 148, 123, 158, 150, 124, 159, 150, 125, 157, 149, 123, 157, 149, 123, 158, 150, 125, 155, 147, 122, 155, 148, 123, 151, 144, 119, 147, 141, 116, | |
146, 136, 113, 143, 134, 111, 148, 137, 114, 152, 143, 119, 155, 145, 120, 156, 147, 122, 154, 146, 121, 155, 147, 122, 155, 147, 122, 154, 146, 121, 151, 143, 118, 148, 141, 117, | |
122, 106, 88, 107, 101, 85, 118, 111, 93, 128, 120, 100, 138, 128, 106, 143, 133, 110, 147, 136, 113, 148, 140, 116, 149, 140, 115, 151, 142, 117, 149, 141, 116, 147, 140, 115, | |
90, 86, 74, 90, 86, 74, 90, 86, 74, 91, 86, 74, 94, 91, 77, 105, 99, 83, 117, 110, 92, 129, 121, 101, 132, 123, 102, 137, 128, 106, 139, 129, 107, 139, 131, 108, | |
89, 86, 75, 89, 85, 76, 89, 86, 75, 89, 86, 75, 90, 86, 75, 90, 86, 74, 90, 86, 74, 91, 86, 73, 91, 86, 74, 97, 92, 77, 107, 101, 85, 116, 109, 91, | |
89, 85, 75, 89, 85, 75, 89, 85, 75, 89, 86, 75, 89, 86, 75, 89, 86, 78, 90, 86, 75, 90, 86, 74, 90, 86, 74, 91, 86, 73, 92, 88, 74, 101, 95, 80, | |
91, 83, 74, 92, 83, 74, 91, 83, 76, 90, 84, 74, 90, 85, 74, 90, 85, 75, 89, 85, 75, 89, 86, 75, 89, 86, 75, 90, 86, 78, 90, 86, 74, 90, 86, 74, | |
92, 82, 73, 93, 82, 73, 92, 83, 73, 91, 83, 74, 91, 84, 74, 90, 84, 74, 90, 85, 74, 90, 85, 75, 89, 85, 75, 89, 86, 75, 90, 86, 75, 90, 86, 75, | |
94, 81, 72, 94, 81, 72, 94, 81, 72, 93, 82, 73, 92, 82, 73, 92, 83, 73, 92, 83, 74, 91, 84, 74, 90, 84, 74, 90, 85, 75, 90, 85, 75, 89, 85, 75, | |
95, 81, 72, 95, 81, 72, 95, 81, 72, 95, 81, 72, 94, 81, 72, 94, 81, 72, 93, 82, 73, 92, 83, 73, 92, 83, 73, 91, 83, 74, 91, 84, 74, 90, 85, 74, | |
95, 80, 72, 95, 81, 72, 95, 80, 72, 95, 81, 72, 95, 81, 72, 95, 81, 72, 94, 81, 72, 94, 81, 72, 93, 82, 72, 93, 82, 73, 92, 83, 73, 92, 83, 73, | |
95, 80, 72, 96, 80, 72, 95, 80, 72, 95, 80, 72, 95, 80, 72, 95, 81, 72, 95, 81, 72, 95, 81, 72, 94, 81, 72, 94, 81, 72, 94, 82, 72, 93, 82, 72] | |
center2 = [450, 706] | |
start2 = [402, 658] | |
data2 = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 227, 237, 236, 211, | |
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
255, 255, 255, 255, 255, 255, 255, 251, 241, 240, 214, 220, 221, 197, | |
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
255, 255, 255, 255, 255, 255, 255, 244, 243, 244, 218, 206, 209, 186, | |
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
255, 255, 255, 255, 253, 255, 255, 232, 226, 228, 204, 191, 194, 174, | |
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
255, 255, 255, 255, 244, 244, 246, 222, 215, 218, 196, 193, 197, 177, | |
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
255, 247, 255, 255, 237, 228, 232, 209, 203, 206, 187, 186, 189, 171, | |
254, 250, 226, 240, 236, 213, 254, 255, 236, 255, 255, 244, 255, 255, 253, 255, 255, 255, 255, 255, 243, 248, | |
250, 226, 239, 242, 219, 224, 217, 197, 193, 196, 178, 179, 183, 166, | |
200, 198, 177, 192, 190, 168, 203, 201, 180, 220, 217, 196, 230, 228, 206, 235, 234, 211, 232, 228, 207, 218, 220, 200, 214, 217, 197, 205, 208, 189, 183, 186, 170, 173, 177, 161, | |
182, 176, 154, 181, 175, 152, 185, 179, 157, 180, 178, 157, 184, 184, 163, 188, 189, 168, 189, 191, 171, 189, 190, 172, 189, 190, 172, 186, 187, 170, 180, 176, 161, 169, 171, 156, | |
175, 167, 142, 176, 168, 143, 177, 169, 145, 176, 169, 146, 176, 171, 149, 170, 166, 146, 162, 162, 142, 162, 162, 146, 164, 165, 147, 166, 166, 149, 166, 166, 150, 162, 163, 148, | |
174, 165, 140, 173, 164, 138, 176, 167, 142, 173, 164, 139, 173, 164, 141, 170, 163, 139, 168, 161, 139, 163, 158, 137, 158, 153, 134, 152, 148, 131, 149, 147, 130, 149, 147, 133, | |
172, 164, 138, 171, 163, 137, 174, 165, 140, 171, 162, 137, 171, 163, 137, 171, 162, 138, 168, 159, 135, 166, 157, 134, 166, 157, 133, 162, 154, 133, 158, 151, 132, 149, 143, 126] | |
center3 = [104, 450] | |
start3 = [56, 402] | |
data3 = [203, 190, 161, 201, 188, 160, 199, 186, 158, 199, 186, 158, 203, 190, 162, 199, 187, 158, 201, 187, 159, 195, 180, 153, 176, 165, 140, 135, 132, 113, 98, 100, 88, 82, 86, 76, | |
197, 185, 156, 197, 184, 156, 197, 185, 156, 197, 185, 157, 200, 187, 159, 199, 187, 158, 196, 182, 154, 186, 172, 147, 171, 160, 137, 115, 115, 99, 86, 89, 79, 81, 86, 77, | |
198, 185, 157, 198, 186, 157, 198, 186, 158, 198, 186, 158, 202, 189, 161, 199, 187, 158, 192, 178, 151, 178, 166, 141, 158, 150, 128, 104, 105, 92, 82, 87, 76, 81, 86, 77, | |
200, 187, 159, 201, 188, 159, 201, 189, 161, 199, 186, 158, 202, 189, 160, 199, 186, 158, 186, 173, 147, 166, 157, 133, 135, 132, 112, 106, 107, 93, 81, 86, 77, 82, 86, 77, | |
199, 187, 159, 199, 187, 158, 200, 188, 159, 198, 186, 157, 203, 189, 161, 198, 184, 157, 188, 174, 148, 148, 142, 121, 117, 116, 100, 94, 96, 85, 81, 86, 77, 83, 85, 76, | |
199, 187, 159, 200, 188, 159, 201, 189, 160, 198, 185, 157, 203, 189, 161, 197, 183, 155, 180, 168, 142, 125, 124, 105, 104, 105, 91, 84, 87, 76, 82, 86, 77, 84, 84, 76, | |
198, 186, 158, 200, 188, 159, 199, 187, 159, 197, 185, 157, 200, 186, 158, 192, 178, 151, 172, 161, 136, 128, 125, 106, 95, 96, 84, 83, 86, 76, 82, 86, 76, 86, 84, 75, | |
195, 183, 155, 198, 186, 158, 195, 184, 156, 195, 182, 155, 196, 182, 154, 182, 169, 143, 151, 144, 122, 106, 106, 91, 84, 86, 76, 82, 86, 76, 84, 85, 76, 87, 83, 75, | |
196, 184, 156, 197, 185, 157, 196, 184, 156, 193, 180, 152, 193, 179, 152, 176, 164, 139, 137, 133, 113, 98, 99, 85, 84, 86, 76, 83, 86, 76, 86, 84, 75, 89, 82, 74, | |
196, 183, 155, 196, 184, 156, 196, 183, 155, 190, 176, 149, 184, 171, 144, 172, 161, 136, 112, 111, 95, 85, 87, 76, 83, 86, 76, 73, 74, 66, 88, 83, 74, 90, 82, 73, | |
196, 183, 155, 199, 186, 158, 198, 185, 157, 187, 173, 146, 177, 164, 139, 160, 151, 127, 101, 101, 87, 84, 86, 75, 83, 86, 76, 84, 85, 76, 89, 82, 74, 91, 81, 73, | |
197, 183, 155, 201, 187, 159, 198, 184, 156, 189, 167, 141, 166, 155, 131, 142, 137, 116, 102, 102, 88, 83, 86, 76, 83, 86, 76, 85, 84, 75, 89, 79, 70, 92, 81, 73] | |
center4 = [651, 450] | |
start4 = [603, 402] | |
data4 = [ | |
252, 244, 215, 252, 245, 216, 252, 244, 216, 249, 242, 213, 242, 235, 207, 233, 227, 194, 212, 209, 182, 183, 184, 159, 156, 161, 138, 127, 134, 113, 115, 119, 100, 118, 118, 99, | |
253, 246, 217, 253, 246, 217, 254, 247, 218, 245, 237, 209, 238, 231, 203, 231, 225, 198, 198, 197, 171, 167, 171, 147, 148, 154, 131, 128, 135, 114, 116, 118, 98, 122, 120, 100, | |
254, 246, 217, 255, 247, 218, 255, 248, 219, 240, 233, 205, 232, 226, 199, 223, 219, 192, 199, 198, 173, 153, 158, 135, 135, 142, 121, 120, 126, 106, 120, 119, 99, 124, 121, 100, | |
254, 247, 218, 255, 247, 218, 255, 248, 219, 245, 238, 210, 225, 220, 193, 212, 210, 183, 185, 186, 161, 140, 147, 125, 126, 133, 112, 115, 120, 101, 119, 118, 99, 127, 122, 101, | |
249, 242, 213, 254, 247, 218, 253, 246, 217, 237, 231, 203, 213, 211, 184, 197, 197, 172, 167, 171, 147, 135, 142, 121, 116, 123, 103, 112, 115, 96, 123, 120, 100, 129, 124, 102, | |
246, 239, 211, 253, 245, 216, 248, 241, 213, 227, 223, 196, 208, 206, 180, 180, 183, 159, 150, 156, 134, 123, 131, 111, 110, 115, 97, 114, 115, 96, 124, 120, 99, 129, 123, 102, | |
243, 236, 208, 253, 245, 216, 242, 236, 208, 216, 213, 187, 196, 196, 171, 166, 170, 147, 137, 144, 123, 115, 122, 104, 108, 113, 96, 117, 116, 97, 127, 121, 100, 131, 125, 103, | |
236, 231, 203, 249, 241, 213, 230, 226, 199, 198, 198, 173, 178, 181, 157, 159, 164, 142, 121, 129, 109, 107, 113, 95, 106, 109, 92, 123, 119, 99, 132, 125, 104, 135, 128, 106, | |
230, 225, 198, 242, 236, 208, 231, 227, 200, 184, 186, 162, 165, 169, 146, 145, 152, 130, 112, 119, 101, 104, 108, 91, 109, 110, 92, 121, 117, 98, 134, 127, 105, 137, 130, 107, | |
219, 216, 190, 232, 227, 200, 216, 214, 188, 166, 170, 148, 149, 154, 133, 131, 138, 118, 111, 118, 101, 104, 106, 90, 117, 115, 96, 127, 121, 101, 137, 130, 107, 138, 131, 108, | |
206, 205, 180, 218, 216, 190, 199, 199, 175, 166, 170, 148, 136, 142, 122, 120, 127, 109, 105, 111, 94, 112, 111, 93, 122, 118, 98, 130, 124, 102, 137, 130, 107, 139, 133, 109, | |
181, 183, 160, 204, 203, 179, 182, 184, 161, 151, 156, 135, 132, 131, 113, 113, 119, 101, 102, 106, 90, 111, 110, 93, 126, 121, 100, 134, 127, 105, 138, 132, 109, 139, 133, 110] | |
data = [data1, data2, data3, data4] | |
starts = [start1, start2, start3, start4] | |
start1 = (643, 402) | |
data1 = [42, 83, 124, 43, 83, 123, 44, 83, 123, 52, 84, 114, 60, 84, 106, 66, 83, 99, 83, 89, 92, 101, 101, 95, 109, 106, 96, 125, 119, 104, 132, 126, 104, 132, 126, 104, | |
42, 83, 124, 41, 83, 125, 43, 83, 124, 48, 84, 117, 53, 84, 112, 59, 84, 107, 68, 83, 96, 90, 94, 94, 94, 96, 92, 118, 114, 101, 132, 126, 105, 133, 127, 105, | |
41, 83, 125, 41, 83, 126, 41, 83, 125, 44, 83, 122, 49, 84, 117, 53, 84, 112, 62, 84, 104, 81, 90, 97, 85, 92, 94, 109, 108, 99, 126, 121, 104, 131, 125, 105, | |
41, 83, 126, 40, 83, 126, 41, 83, 126, 42, 83, 124, 46, 84, 120, 49, 84, 117, 56, 84, 110, 67, 84, 100, 75, 87, 96, 97, 100, 96, 121, 117, 103, 128, 123, 104, | |
41, 83, 126, 40, 83, 126, 40, 83, 126, 42, 83, 125, 43, 83, 123, 46, 84, 120, 51, 84, 114, 60, 84, 105, 67, 84, 98, 90, 96, 97, 114, 112, 102, 122, 118, 103, | |
40, 83, 126, 40, 83, 127, 40, 83, 126, 41, 83, 125, 42, 83, 124, 44, 84, 121, 49, 84, 116, 57, 84, 108, 61, 84, 104, 87, 95, 98, 107, 107, 99, 117, 114, 102, | |
40, 83, 127, 40, 83, 127, 40, 83, 127, 41, 83, 126, 41, 83, 125, 42, 84, 124, 46, 84, 119, 52, 84, 113, 56, 84, 110, 79, 91, 100, 96, 100, 97, 106, 107, 99, | |
40, 83, 127, 40, 83, 127, 40, 83, 127, 40, 83, 126, 41, 83, 126, 41, 84, 125, 46, 85, 122, 50, 84, 115, 53, 84, 112, 64, 84, 102, 92, 97, 97, 101, 103, 98, | |
40, 83, 127, 40, 83, 127, 40, 83, 127, 40, 83, 125, 40, 83, 126, 41, 83, 125, 42, 84, 124, 46, 84, 119, 49, 84, 116, 58, 84, 107, 75, 92, 97, 90, 96, 97, | |
40, 82, 126, 40, 83, 127, 40, 83, 127, 40, 83, 127, 40, 83, 126, 40, 83, 126, 41, 84, 124, 44, 85, 121, 48, 84, 117, 57, 84, 108, 72, 87, 98, 86, 93, 96, | |
40, 83, 127, 40, 83, 127, 39, 83, 127, 40, 83, 127, 40, 83, 127, 40, 83, 126, 41, 84, 125, 43, 84, 122, 46, 84, 120, 53, 84, 111, 65, 84, 100, 73, 88, 95, | |
40, 83, 127, 40, 83, 126, 39, 83, 127, 39, 83, 127, 39, 83, 127, 40, 83, 126, 41, 84, 125, 42, 84, 123, 44, 84, 121, 52, 84, 113, 63, 84, 102, 68, 84, 97], | |
start2 = (116, 402) | |
data2 = [190, 178, 154, 196, 182, 157, 182, 171, 149, 146, 147, 134, 106, 119, 116, 86, 98, 105, 55, 86, 105, 49, 85, 112, 48, 85, 115, 46, 84, 117, 46, 84, 118, 46, 84, 118, | |
190, 177, 152, 198, 185, 158, 193, 172, 149, 153, 151, 137, 129, 135, 127, 104, 117, 115, 57, 86, 103, 50, 85, 111, 48, 85, 114, 47, 83, 115, 46, 84, 118, 46, 84, 118, | |
191, 179, 153, 197, 184, 157, 192, 180, 154, 164, 159, 142, 149, 150, 138, 126, 134, 127, 76, 99, 103, 52, 86, 108, 49, 85, 112, 47, 85, 115, 46, 84, 118, 46, 84, 118, | |
195, 182, 156, 201, 188, 161, 196, 183, 157, 182, 172, 145, 162, 159, 143, 143, 146, 136, 84, 104, 109, 54, 86, 106, 51, 86, 110, 48, 85, 114, 46, 84, 116, 46, 84, 118, | |
194, 181, 157, 198, 186, 159, 195, 183, 156, 188, 177, 154, 172, 166, 148, 152, 152, 138, 95, 112, 113, 64, 91, 103, 53, 86, 107, 49, 85, 113, 46, 85, 117, 45, 84, 118, | |
194, 183, 156, 198, 185, 158, 195, 183, 157, 190, 178, 155, 182, 172, 152, 161, 158, 141, 107, 121, 118, 72, 97, 108, 56, 86, 104, 50, 85, 111, 47, 85, 116, 46, 84, 118, | |
193, 181, 155, 196, 185, 157, 193, 182, 155, 187, 177, 152, 181, 172, 150, 165, 160, 142, 117, 127, 123, 79, 102, 110, 66, 93, 106, 51, 86, 109, 47, 85, 115, 46, 84, 118, | |
193, 182, 155, 195, 184, 156, 193, 182, 155, 183, 173, 148, 188, 177, 154, 185, 175, 153, 136, 140, 131, 93, 111, 114, 77, 101, 110, 53, 86, 106, 48, 85, 114, 46, 85, 117, | |
194, 182, 155, 196, 185, 157, 196, 184, 157, 191, 180, 154, 192, 180, 156, 189, 178, 154, 149, 149, 137, 105, 120, 118, 87, 108, 113, 67, 95, 108, 48, 85, 113, 46, 85, 117, | |
193, 182, 154, 195, 184, 156, 195, 183, 156, 193, 181, 155, 194, 182, 157, 192, 180, 155, 174, 166, 146, 123, 132, 126, 98, 115, 116, 74, 100, 110, 49, 86, 111, 46, 85, 116, | |
193, 181, 154, 195, 183, 156, 195, 183, 156, 194, 182, 155, 195, 182, 156, 194, 182, 156, 181, 171, 149, 141, 144, 134, 115, 126, 122, 84, 106, 112, 57, 88, 106, 47, 85, 114, | |
195, 183, 156, 195, 183, 156, 196, 184, 157, 194, 182, 155, 197, 184, 158, 196, 183, 157, 187, 176, 153, 165, 160, 143, 136, 141, 132, 93, 112, 115, 64, 94, 109, 47, 83, 108] | |
start3 = (402, 156) | |
data3 = [160, 152, 127, 158, 150, 126, 158, 150, 125, 158, 150, 125, 158, 150, 125, 156, 148, 123, 156, 149, 125, 157, 149, 125, 154, 146, 121, 152, 145, 121, 146, 139, 116, 143, 137, 115, | |
158, 151, 126, 160, 152, 128, 159, 152, 127, 158, 150, 126, 158, 150, 125, 157, 149, 125, 155, 148, 124, 153, 146, 123, 151, 144, 121, 146, 140, 119, 139, 135, 115, 132, 129, 111, | |
159, 151, 127, 161, 153, 128, 161, 153, 129, 159, 151, 127, 157, 150, 126, 158, 150, 127, 153, 146, 124, 145, 140, 120, 139, 136, 117, 131, 130, 114, 120, 122, 109, 106, 112, 104, | |
159, 152, 128, 161, 153, 129, 161, 153, 129, 159, 151, 128, 156, 148, 126, 155, 148, 126, 148, 143, 122, 139, 136, 119, 130, 129, 114, 123, 124, 111, 110, 115, 106, 99, 107, 102, | |
154, 148, 126, 158, 150, 127, 155, 148, 127, 147, 143, 124, 141, 138, 121, 134, 134, 120, 121, 124, 114, 105, 114, 109, 97, 108, 106, 77, 93, 96, 68, 87, 94, 63, 87, 99, | |
127, 129, 116, 138, 136, 120, 125, 128, 116, 110, 118, 111, 100, 112, 108, 89, 104, 103, 68, 88, 96, 62, 87, 100, 60, 87, 102, 55, 86, 107, 52, 86, 110, 50, 85, 113, | |
116, 122, 113, 127, 129, 116, 118, 124, 114, 90, 104, 103, 78, 96, 99, 71, 91, 97, 61, 87, 101, 56, 86, 106, 55, 86, 108, 52, 86, 110, 49, 85, 115, 47, 85, 117, | |
73, 92, 98, 85, 101, 102, 72, 92, 99, 58, 84, 99, 57, 86, 106, 54, 86, 108, 51, 86, 111, 48, 85, 116, 47, 85, 117, 46, 85, 118, 44, 83, 119, 44, 84, 121, | |
63, 90, 105, 65, 88, 97, 59, 87, 103, 54, 86, 108, 51, 86, 112, 49, 85, 114, 47, 85, 117, 45, 84, 119, 45, 84, 120, 44, 84, 121, 44, 84, 121, 43, 84, 123, | |
50, 86, 113, 54, 86, 108, 50, 86, 112, 48, 85, 116, 47, 85, 118, 45, 85, 119, 45, 84, 120, 44, 84, 121, 43, 84, 122, 43, 84, 122, 43, 84, 123, 43, 83, 122, | |
46, 85, 118, 48, 85, 116, 46, 85, 118, 45, 84, 120, 44, 84, 121, 44, 84, 121, 44, 84, 121, 44, 84, 122, 44, 83, 121, 44, 84, 122, 43, 83, 122, 43, 83, 123, | |
44, 84, 121, 45, 84, 120, 44, 84, 121, 43, 84, 122, 43, 84, 122, 43, 84, 122, 44, 84, 121, 45, 83, 121, 45, 83, 120, 45, 83, 120, 45, 83, 120, 44, 83, 121] | |
start4 = (402, 678) | |
data4 = [45, 84, 121, 45, 84, 121, 45, 84, 121, 45, 84, 121, 45, 84, 121, 45, 84, 121, 45, 84, 121, 44, 84, 121, 44, 84, 121, 44, 84, 121, 45, 84, 120, 45, 84, 120, | |
45, 84, 121, 45, 84, 121, 45, 84, 121, 45, 84, 121, 45, 84, 120, 45, 84, 121, 45, 84, 121, 45, 84, 120, 45, 84, 120, 46, 84, 119, 47, 84, 118, 48, 84, 115, | |
45, 84, 120, 45, 84, 121, 45, 84, 121, 45, 84, 120, 46, 84, 120, 45, 84, 120, 45, 84, 119, 46, 84, 118, 47, 84, 117, 48, 84, 115, 50, 84, 113, 55, 85, 111, | |
46, 84, 120, 46, 84, 120, 46, 84, 120, 46, 84, 119, 46, 84, 118, 47, 84, 118, 48, 84, 116, 50, 84, 113, 53, 85, 112, 55, 84, 108, 58, 84, 105, 61, 84, 101, | |
47, 84, 118, 46, 84, 119, 47, 84, 118, 48, 84, 117, 49, 84, 115, 50, 85, 114, 54, 84, 109, 57, 84, 105, 59, 84, 103, 66, 86, 101, 73, 90, 102, 82, 96, 103, | |
49, 84, 115, 48, 84, 116, 49, 85, 116, 52, 84, 111, 55, 84, 109, 57, 84, 106, 63, 84, 100, 72, 90, 102, 77, 93, 103, 84, 100, 105, 100, 107, 108, 116, 119, 115, | |
54, 84, 109, 52, 84, 112, 54, 84, 109, 60, 84, 102, 64, 84, 99, 69, 87, 100, 78, 93, 103, 96, 105, 107, 103, 110, 109, 117, 120, 116, 132, 131, 121, 141, 137, 124, | |
62, 84, 101, 59, 84, 104, 63, 84, 100, 69, 86, 99, 84, 96, 102, 91, 101, 105, 103, 110, 109, 130, 129, 121, 134, 132, 122, 140, 137, 123, 145, 140, 126, 153, 146, 127, | |
85, 96, 101, 72, 87, 97, 83, 95, 101, 96, 103, 104, 117, 119, 114, 127, 127, 119, 137, 134, 122, 145, 140, 125, 150, 144, 127, 153, 146, 127, 155, 148, 127, 158, 151, 129, | |
113, 115, 110, 95, 102, 102, 113, 115, 111, 128, 127, 117, 138, 134, 122, 145, 140, 124, 150, 144, 126, 155, 148, 128, 157, 150, 129, 159, 152, 129, 159, 151, 129, 160, 152, 129, | |
139, 135, 120, 129, 126, 116, 143, 137, 123, 147, 140, 123, 153, 145, 126, 157, 149, 128, 157, 149, 127, 158, 151, 128, 159, 152, 128, 160, 153, 129, 160, 152, 129, 161, 154, 130, | |
152, 144, 125, 147, 140, 122, 155, 147, 127, 155, 147, 126, 158, 151, 128, 160, 152, 129, 158, 150, 127, 158, 151, 127, 159, 151, 127, 159, 151, 127, 158, 151, 127, 160, 153, 128] | |
data = [data1, data2, data3, data4] | |
starts = [start1, start2, start3, start4] | |
BOARD_HEIGHT = 900 | |
BOARD_WIDTH = 900 | |
STEP = 8 | |
board = np.zeros(shape=[int(BOARD_HEIGHT/STEP), | |
int(BOARD_WIDTH/STEP)], dtype='uint8') | |
for d, s in zip(data, starts): | |
arr = np.array(d, dtype='uint8').reshape(12, 12, 3) | |
img = cv2.cvtColor(arr, cv2.COLOR_RGB2BGR) | |
s = [int(x / 8) for x in s] | |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
edges = cv2.Canny(gray, 200, 255, True, apertureSize=3) | |
board[s[1]: s[1]+12, s[0]: s[0]+12] = edges | |
lines = cv2.HoughLinesP(board, rho=1, theta=np.pi / 180, | |
threshold=8, minLineLength=5, maxLineGap=2) | |
boardColour = cv2.cvtColor(board, cv2.COLOR_GRAY2BGR) | |
cartLines = [] | |
for line in lines: | |
for [x1, y1, x2, y2] in line: | |
print(x1, y1, 'to', x2, y2) | |
gradient = (y2-y1)/(x2-x1) | |
intercept = y1 - x1 * gradient | |
cartLines.append((gradient, intercept)) | |
print('gradient', gradient, 'int', intercept) | |
p1 = (0, int(intercept)) | |
p2 = (board.shape[0], int(board.shape[1] * gradient + intercept)) | |
print('line from', p1, p2) | |
cv2.line(boardColour, p1, p2, (0, 255, 0), 1) | |
cv2.line(boardColour, (x1, y1), (x2, y2), (255, 0, 0), 1) | |
def intersection(m1: float, b1: float, m2: float, b2: float): | |
x = (b2 - b1) / (m1 - m2) | |
y = m1 * x + b1 | |
return int(round(x)), int(round(y)) | |
intpoints = [] | |
intlines = set() | |
for l1, l2 in itertools.permutations(cartLines, 2): | |
x, y = intersection(l1[0], l1[1], l2[0], l2[1]) | |
if x > board.shape[1] or y > board.shape[0]: | |
continue | |
theta = math.atan((l2[0] - l1[0]) / (1 + l2[0] * l1[0])) * 180/np.pi | |
thresh = 20 | |
if 90 - theta > thresh: | |
continue | |
print(theta) | |
intlines.update([l1, l2]) | |
intpoints.append([x, y]) | |
boardColour[y, x] = [0, 0, 255] | |
if len(intpoints) > 2: | |
rect = cv2.minAreaRect(np.array(intpoints)) | |
box = cv2.boxPoints(rect) | |
box = np.int0(box) | |
cv2.drawContours(boardColour, [box], 0, (0, 0, 255), 1) | |
print(intlines) | |
for l1, l2, l3 in itertools.combinations(intlines, 3): | |
# need two almost parallel lines | |
for pl1, pl2, pl3 in itertools.permutations([l1, l2, l3], 3): | |
theta1 = abs(math.atan((pl2[0] - pl1[0]) / | |
(1 + pl2[0] * pl1[0])) * 180/np.pi) | |
theta2 = abs(math.atan((pl3[0] - pl1[0]) / | |
(1 + pl3[0] * pl1[0])) * 180/np.pi) | |
theta3 = abs(math.atan((pl3[0] - pl2[0]) / | |
(1 + pl3[0] * pl2[0])) * 180/np.pi) | |
thetaavg = (theta2 + theta3) / 2 | |
if not(theta1 < 10 and 90 - thetaavg < 15): | |
continue | |
print('\n', pl1, pl2, pl3) | |
print(theta1, theta2, theta3, thetaavg) | |
x1, y1 = intersection(pl1[0], pl1[1], pl3[0], pl3[0]) | |
x2, y2 = intersection(pl2[0], pl2[1], pl3[0], pl3[0]) | |
dist = math.sqrt((x2 - x1)**2+(y2-y1)**2) | |
cv2.circle(boardColopyur, (x1, y1), int(dist), (255, 255, 255)) | |
print(x1, y1, x2, y2, dist) | |
def order_points(pts): | |
# initialzie a list of coordinates that will be ordered | |
# such that the first entry in the list is the top-left, | |
# the second entry is the top-right, the third is the | |
# bottom-right, and the fourth is the bottom-left | |
rect = np.zeros((4, 2), dtype="float32") | |
# the top-left point will have the smallest sum, whereas | |
# the bottom-right point will have the largest sum | |
s = pts.sum(axis=1) | |
rect[0] = pts[np.argmin(s)] | |
rect[2] = pts[np.argmax(s)] | |
# now, compute the difference between the points, the | |
# top-right point will have the smallest difference, | |
# whereas the bottom-left will have the largest difference | |
diff = np.diff(pts, axis=1) | |
rect[1] = pts[np.argmin(diff)] | |
rect[3] = pts[np.argmax(diff)] | |
# return the ordered coordinates | |
return rect | |
def four_point_transform(image, pts): | |
# obtain a consistent order of the points and unpack them | |
# individually | |
rect = order_points(pts) | |
(tl, tr, br, bl) = rect | |
# compute the width of the new image, which will be the | |
# maximum distance between bottom-right and bottom-left | |
# x-coordiates or the top-right and top-left x-coordinates | |
widthA = np.sqrt(((br[0] - bl[0]) ** 2) + ((br[1] - bl[1]) ** 2)) | |
widthB = np.sqrt(((tr[0] - tl[0]) ** 2) + ((tr[1] - tl[1]) ** 2)) | |
maxWidth = max(int(widthA), int(widthB)) | |
# compute the height of the new image, which will be the | |
# maximum distance between the top-right and bottom-right | |
# y-coordinates or the top-left and bottom-left y-coordinates | |
heightA = np.sqrt(((tr[0] - br[0]) ** 2) + ((tr[1] - br[1]) ** 2)) | |
heightB = np.sqrt(((tl[0] - bl[0]) ** 2) + ((tl[1] - bl[1]) ** 2)) | |
maxHeight = max(int(heightA), int(heightB)) | |
# now that we have the dimensions of the new image, construct | |
# the set of destination points to obtain a "birds eye view", | |
# (i.e. top-down view) of the image, again specifying points | |
# in the top-left, top-right, bottom-right, and bottom-left | |
# order | |
dst = np.array([ | |
[0, 0], | |
[maxWidth - 1, 0], | |
[maxWidth - 1, maxHeight - 1], | |
[0, maxHeight - 1]], dtype="float32") | |
# compute the perspective transform matrix and then apply it | |
M = cv2.getPerspectiveTransform(rect, dst) | |
warped = cv2.warpPerspective(image, M, (image.shape[1], image.shape[0])) | |
# return the warped image | |
return warped | |
# points = np.int32(order_points(np.array(intpoints))) | |
# cv2.polylines(boardColour, [points], True, (0, 255, 255)) | |
# warped = four_point_transform(boardColour, points) | |
cv2.namedWindow('image', cv2.WINDOW_NORMAL) | |
cv2.resizeWindow('image', 600, 600) | |
# cv2.namedWindow('warped', cv2.WINDOW_NORMAL) | |
# cv2.resizeWindow('warped', 600, 600) | |
# cv2.imshow('warped', warped) | |
cv2.imshow('image', boardColour) | |
cv2.waitKey(1) | |
input('any key to close') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment