Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Julian Steenbakker
2022-12-22 08:45:41 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
71701bb945ed52b68cc658ecca0ad38c148b1365
71701bb9
1 parent
cb853313
imp: fix build on macos
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
23 deletions
example/macos/Runner.xcworkspace/contents.xcworkspacedata
example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
macos/Classes/DetectionSpeed.swift
macos/Classes/MobileScannerPlugin.swift
example/macos/Runner.xcworkspace/contents.xcworkspacedata
0 → 100644
View file @
71701bb
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version =
"1.0"
>
<FileRef
location =
"group:Runner.xcodeproj"
>
</FileRef>
<FileRef
location =
"group:Pods/Pods.xcodeproj"
>
</FileRef>
</Workspace>
...
...
example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
0 → 100644
View file @
71701bb
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist
version=
"1.0"
>
<dict>
<key>
IDEDidComputeMac32BitWarning
</key>
<true/>
</dict>
</plist>
...
...
macos/Classes/DetectionSpeed.swift
0 → 100644
View file @
71701bb
//
// DetectionSpeed.swift
// mobile_scanner
//
// Created by Julian Steenbakker on 11/11/2022.
//
enum
DetectionSpeed
:
Int
{
case
noDuplicates
=
0
case
normal
=
1
case
unrestricted
=
2
}
...
...
macos/Classes/MobileScannerPlugin.swift
View file @
71701bb
import
AVFoundation
import
FlutterMacOS
import
Vision
import
UI
Kit
import
App
Kit
public
class
MobileScannerPlugin
:
NSObject
,
FlutterPlugin
,
FlutterStreamHandler
,
FlutterTexture
,
AVCaptureVideoDataOutputSampleBufferDelegate
{
...
...
@@ -25,6 +25,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
// optional window to limit scan search
var
scanWindow
:
CGRect
?
var
detectionSpeed
:
DetectionSpeed
=
DetectionSpeed
.
noDuplicates
// var analyzeMode: Int = 0
var
analyzing
:
Bool
=
false
...
...
@@ -93,20 +95,15 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
// Gets called when a new image is added to the buffer
public
func
captureOutput
(
_
output
:
AVCaptureOutput
,
didOutput
sampleBuffer
:
CMSampleBuffer
,
from
connection
:
AVCaptureConnection
)
{
i
=
i
+
1
;
latestBuffer
=
CMSampleBufferGetImageBuffer
(
sampleBuffer
)
guard
let
imageBuffer
=
CMSampleBufferGetImageBuffer
(
sampleBuffer
)
else
{
print
(
"Failed to get image buffer from sample buffer."
)
return
}
latestBuffer
=
imageBuffer
registry
.
textureFrameAvailable
(
textureId
)
// switch analyzeMode {
// case 1: // barcode
// Limit the analyzer because the texture output will freeze otherwise
if
i
/
10
==
1
{
if
((
detectionSpeed
==
DetectionSpeed
.
normal
||
detectionSpeed
==
DetectionSpeed
.
noDuplicates
)
&&
i
>
10
||
detectionSpeed
==
DetectionSpeed
.
unrestricted
)
{
i
=
0
}
else
{
return
}
let
imageRequestHandler
=
VNImageRequestHandler
(
cvPixelBuffer
:
latestBuffer
,
orientation
:
.
right
)
...
...
@@ -116,8 +113,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
if
error
==
nil
{
if
let
results
=
request
.
results
as?
[
VNBarcodeObservation
]
{
for
barcode
in
results
{
if
scanWindow
!=
nil
{
let
match
=
isbarCodeInScanWindow
(
scanWindow
!
,
barcode
,
buffer
!.
image
)
if
self
.
scanWindow
!=
nil
{
let
match
=
self
.
isbarCodeInScanWindow
(
self
.
scanWindow
!
,
barcode
,
self
.
latestBuffer
)
if
(
!
match
)
{
continue
}
...
...
@@ -141,10 +138,9 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
}
catch
{
print
(
error
)
}
// default: // none
// break
// }
}
else
{
i
+=
1
}
}
func
checkPermission
(
_
call
:
FlutterMethodCall
,
_
result
:
@escaping
FlutterResult
)
{
...
...
@@ -188,11 +184,11 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
scanWindow
=
CGRect
(
x
:
minX
,
y
:
minY
,
width
:
width
,
height
:
height
)
}
func
isbarCodeInScanWindow
(
_
scanWindow
:
CGRect
,
_
barcode
:
Barcode
,
_
inputImage
:
UIImage
)
->
Bool
{
let
barcodeBoundingBox
=
barcode
.
frame
func
isbarCodeInScanWindow
(
_
scanWindow
:
CGRect
,
_
barcode
:
VNBarcodeObservation
,
_
inputImage
:
CVImageBuffer
)
->
Bool
{
let
size
=
CVImageBufferGetEncodedSize
(
inputImage
)
let
imageWidth
=
inputImage
.
size
.
width
;
let
imageHeight
=
inputImage
.
size
.
height
;
let
imageWidth
=
size
.
width
;
let
imageHeight
=
size
.
height
;
let
minX
=
scanWindow
.
minX
*
imageWidth
let
minY
=
scanWindow
.
minY
*
imageHeight
...
...
@@ -200,7 +196,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
let
height
=
scanWindow
.
height
*
imageHeight
let
scaledScanWindow
=
CGRect
(
x
:
minX
,
y
:
minY
,
width
:
width
,
height
:
height
)
return
scaledScanWindow
.
contains
(
barcode
B
oundingBox
)
return
scaledScanWindow
.
contains
(
barcode
.
b
oundingBox
)
}
func
start
(
_
call
:
FlutterMethodCall
,
_
result
:
@escaping
FlutterResult
)
{
...
...
@@ -219,6 +215,9 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
// let ratio: Int = argReader.int(key: "ratio")
let
torch
:
Bool
=
argReader
.
bool
(
key
:
"torch"
)
??
false
let
facing
:
Int
=
argReader
.
int
(
key
:
"facing"
)
??
1
let
speed
:
Int
=
(
call
.
arguments
as!
Dictionary
<
String
,
Any
?
>
)[
"speed"
]
as?
Int
??
0
detectionSpeed
=
DetectionSpeed
(
rawValue
:
speed
)
!
// Set the camera to use
position
=
facing
==
0
?
AVCaptureDevice
.
Position
.
front
:
.
back
...
...
Please
register
or
login
to post a comment