Flipping image causes massive RAM/CPU uses with AForge.net - aforge

Hey all i am trying to figure out why when i flip the image it uses a LOT of RAM and CPU (its an quad core i7)
I use this code:
Dim filter As New RotateBilinear(180, True)
image = Filter.Apply(image)
If bIsToRecord Then
If writer Is Nothing Then
Dim [date] As DateTime = DateTime.Now
Dim fileName As [String] = [String].Format("{0},{1}.avi",[date].Minute, [date].Second)
Try
OpenWriter(fileName, image.Width, image.Height)
Catch ex As Exception
If writer IsNot Nothing Then
writer.Dispose()
writer = Nothing
End If
End Try
End If
Try
If radioButton1.Checked Then
writer.AddFrame(image)
Else
mVideoFileWriter.WriteVideoFrame(image)
End If
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.ToString())
End Try
End If
That is WITHOUT flipping the images
WITH the flipping...
Each screenshot was for 30 seconds.
What could be causing this?

Related

Change font size; checklist box items are on top of each other

We remote into our work environment. When working from home the monitor scale looks different than at work. I've spent hours trying to get them to look the same and failed. So I would like to add a scaler(font increaser/decreaser) to my program. The concept is to change the font size of the form and the rest will scale. It seems to work fine except the checklist box(See screenshots). The items are almost stacked on top of each other. I can't seem to get it to update or redraw itself. I'm writing in VB.NET by the way(I know:)). I've tried CheckListBox.Update(); CheckListBox.Refresh(); CheckListBox.ResetText() and all have failed. Is there a way to separate them? perhaps my approach is wrong. What do you think?
Initial Run Tiny
Scale up
VB.NET
Private Sub Btn_Scale_Up_Click(sender As Object, e As EventArgs) Handles Btn_Scale_Up.Click
Dim FntSize as Integer = Font.Size
FntSize += 1
Me.Font = New Font("Arial", FntSize)
FrmResize.ResizeAllControls(Me)
'CLBox_ColumsForDescription.Update()
'CLBox_ColumnsForDescription.Refresh()
'CLBox_ColumnsForDescription.ResetText()
Me.Update()
End Sub
Private Sub Btn_Scale_Down_Click(sender As Object, e As EventArgs) Handles Btn_Scale_Down.Click
Dim FntSize as Integer = Font.Size
FntSize -= 1
Me.Font = New Font("Arial", FntSize)
FrmResize.ResizeAllControls(Me)
'CLBox_ColumsForDescription.Update()
'CLBox_ColumnsForDescription.Refresh()
'CLBox_ColumnsForDescription.ResetText()
Me.Update()
End Sub
Public Class ResizerForm1
Public Sub ResizeAllControls(ThisCtrl as Control)
For Each Ctl as Control in ThisCtrl.Controls
If Ctl.Name.Contains("CLBox_ColumsForDescription") Then
'--Size
Ctl.Width = Int(ParentWidth - Ctl.Location.X - 30)
Ctl.Height = Int(ParentHeight - Ctl.Location.Y - (ParentHeight - Ctl.Parent.Controls.Item("Btn_Below").Location.Y))
'--Position
Ctl.Top = Int(Ctl.Parent.Controls.Item("TxtBox_Above").Location.Y + Ctl.Parent.Controls.Item("TxtBox_Above").Height + 5)
Ctl.Left = 15
'Ctl.Update()
'Ctl.Refresh()
End If
Next
End Sub
End Class

Update error on a recordset ADODB with VB.net

I try-ing to update application but when debugging everything goes well. But updating the records is not working anymore.
The error I get is: System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
public Sub LoginRegistration()
Dim RSReturn As New ADODB.Recordset
Dim SQLString As String = "SELECT tbllogin.idtbllogin, tbllogin.Log_date, tbllogin.Log_user FROM tbllogin LIMIT 1;"
Try
RSReturn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
RSReturn.CursorType = ADODB.CursorTypeEnum.adOpenDynamic
RSReturn.LockType = ADODB.LockTypeEnum.adLockOptimistic
RSReturn.Open(SQLString, cn)
RSReturn.AddNew()
RSReturn.Fields.Item("Log_date").Value = Now()
RSReturn.Fields.Item("Log_user").Value = "Harold" 'Environment.UserName
RSReturn.Update()
Catch ex As Exception
MsgBox(ex.Message, ex.StackTrace)
Finally
RSReturn.Close()
RSReturn = Nothing
End Try
End Sub```

Extracting motion detector blob

Edit: Motion Detection I believe this may answer my question...
I want to not only detect motion, but read where the motion occurred in the frame. Nothing in MotionDetector seems to have anything about its location. I thought maybe I could run it through MotionDetector then extract the biggest blob, but that doesn't seem to work either. It only picks up one blob.
Video clip is a vehicle coming down a ramp. mainPBX is the original frame, main2PBX is the altered frame (with the biggest blob overlayed). My thought is to read when the blob goes from smaller to bigger (and vice versa), to determine entering or leaving.
Private Sub Processor()
Dim bc As New BlobCounter With {
.MinWidth = 5,
.MinHeight = 5,
.ObjectsOrder = ObjectsOrder.Size
}
Dim detector As New MotionDetector(New SimpleBackgroundModelingDetector, New MotionAreaHighlighting)
Using reader As New AForge.Video.FFMPEG.VideoFileReader()
reader.Open("C:\Videos\MyVideo.mp4")
For i As Integer = 0 To reader.FrameCount - 1
Dim frame = reader.ReadVideoFrame()
Dim frame2 As Bitmap = frame.Clone()
Dim frame3 As Bitmap = frame.Clone()
detector.ProcessFrame(frame2)
bc.ProcessImage(frame2)
Dim blobs = bc.GetObjectsInformation()
If blobs.Length > 0 Then
bc.ExtractBlobsImage(frame3, blobs(0), True)
PBX_Image(main2PBX, frame3.Clone())
End If
PBX_Image(mainPBX, frame.Clone())
Threading.Thread.Sleep(25)
frame.Dispose()
frame2.Dispose()
frame3.Dispose()
Next
End Using
End Sub
This is in no way finished, but I can actually interact with the blobs.
Private Sub Processor()
Dim Rectangles As New List(Of Rectangle)
Dim detector As New SimpleBackgroundModelingDetector With {
.SuppressNoise = True,
.DifferenceThreshold = 10,
.FramesPerBackgroundUpdate = 10,
.KeepObjectsEdges = True
}
Dim processor As New AForge.Vision.Motion.BlobCountingObjectsProcessing With {
.MinObjectsWidth = 40,
.MinObjectsHeight = 40,
.HighlightColor = Color.Red
}
Dim motionDetector As New MotionDetector(detector, processor)
Using reader As New AForge.Video.FFMPEG.VideoFileReader()
reader.Open("C:\Videos\MyVideo.mp4")
For i As Integer = 0 To reader.FrameCount - 1
Dim frame = reader.ReadVideoFrame()
motionDetector.ProcessFrame(frame)
Dim t As BlobCountingObjectsProcessing = motionDetector.MotionProcessingAlgorithm
Dim r As Rectangle = Rectangle.Empty
If t.ObjectRectangles.Length > 0 Then
If t.ObjectRectangles.Length > 2 Then
r = t.ObjectRectangles.Aggregate(Function(r1, r2) If((r1.Width * r1.Height) > (r2.Width * r2.Height), r1, r2))
Else
r = t.ObjectRectangles.First()
End If
End If
If r.IsEmpty = False Then Rectangles.Add(r)
PBX_Image(mainPBX, frame.Clone())
Threading.Thread.Sleep(25)
frame.Dispose()
Next
End Using
End Sub

Google Closure Compile REST Api suddenly Throws Error 405 "Method not allowed"

I've been using Closure as part of y application to compress Javascript for a while now, but just started getting an error 405 - Method not allowed
My code as below was working for a couple of years, but has now stopped.
NOTE: this is not called frequently, just when ever any changes are detected in the Javascript files in my application.
I get no further error information from the Closure app than this.
Obviously this code performs a POST operation. If I use the form found here https://closure-compiler.appspot.com/home, it works, but if I either browser to the URL or use my code I get Error 405, it's almost as if my code is trying a GET method... but it's not...
Any ideas?
Public Class Closure
Property OriginalCode As String
Property CompiledCode As String
Property Errors As ArrayList
Property Warnings As ArrayList
Property Statistics As Dictionary(Of String, Object)
Public Sub New(Input As String, Optional CompliationLevel As String = "SIMPLE_OPTIMIZATIONS")
Dim _HttpWebRequest As HttpWebRequest
Dim _Result As StringBuilder
Dim ClosureWebServiceURL As String = "http://closure-compiler.appspot.com/compile?"
Dim ClosureWebServicePOSTData As String = "output_format=json&output_info=compiled_code" &
"&output_info=warnings" &
"&output_info=errors" &
"&output_info=statistics" &
"&compilation_level=" & CompliationLevel & "" &
"&warning_level=default" &
"&js_code={0}"
'// Create the POST data
Dim Data = String.Format(ClosureWebServicePOSTData, HttpUtility.UrlEncode(Input))
_Result = New StringBuilder
_HttpWebRequest = DirectCast(WebRequest.Create(ClosureWebServiceURL), HttpWebRequest)
_HttpWebRequest.Method = "POST"
_HttpWebRequest.ContentType = "application/x-www-form-urlencoded"
'//Set the content length to the length of the data. This might need to change if you're using characters that take more than 256 bytes
_HttpWebRequest.ContentLength = Data.Length
'//Write the request stream
Using SW As New StreamWriter(_HttpWebRequest.GetRequestStream())
SW.Write(Data)
End Using
Try
Dim response As WebResponse = _HttpWebRequest.GetResponse()
Using responseStream As Stream = response.GetResponseStream
Dim encoding As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Using readStream As New StreamReader(responseStream, encoding)
Dim read(256) As Char
Dim count As Integer = readStream.Read(read, 0, 256)
While count > 0
Dim str As New String(read, 0, count)
_Result.Append(str)
count = readStream.Read(read, 0, 256)
End While
End Using
End Using
Dim js As New JavaScriptSerializer
js.MaxJsonLength = Int32.MaxValue
Dim d As Dictionary(Of String, Object) = js.Deserialize(Of Dictionary(Of String, Object))(_Result.ToString())
Me.CompiledCode = d.NullKey("compiledCode")
Me.Warnings = TryCast(d.NullKey("warnings"), ArrayList)
Me.Errors = TryCast(d.NullKey("errors"), ArrayList)
Me.Statistics = TryCast(d.NullKey("statistics"), Dictionary(Of String, Object))
Catch ex As Exception
Me.CompiledCode = ""
If Me.Errors Is Nothing Then
Dim er As New List(Of String)
er.Add(ex.ToString())
Me.Errors = New ArrayList(er)
Else
Me.Errors.Add(ex.ToString())
End If
End Try
Me.OriginalCode = Input
End Sub
End Class
Closure REST api is redirecting to https, you may want to try to POST to "https://closure-compiler.appspot.com/compile" directly in order to avoid redirection.

How to split a multi-frame TIFF image in pagewise in .NET 2.0?

I want to split multlipage tiff image in page wise.
I have written following code.
Dim pagecount, ImagePageCount As Integer
Dim activePage As Integer
Dim sourceImage As System.Drawing.Image = Nothing
Dim fImage As Bitmap = Nothing
Dim pageLoad As Boolean = False
Try
fImage = New Bitmap(tempFilePath)
sourceImage = fImage
pagecount = sourceImage.GetFrameCount(FrameDimension.Page)
pageLoad = True
Catch ex As Exception
pageLoad = False
Throw
End Try
Try
If pageLoad = True Then
If pagecount <> 0 Then
For ImagePageCount = 0 To pagecount - 1
sourceImage.SelectActiveFrame(FrameDimension.Page, ImagePageCount)
activePage = ImagePageCount + 1
Dim img1 As Drawing.Bitmap = CType(sourceImage.Clone, Drawing.Bitmap)
Dim tempPageFile As String = Path.Combine(Path.GetTempPath(), String.Format("{0}_{1}_{2:00000000}_{3}.tif", Convert.ToString(indexEntry.GetFrameNumber()), Convert.ToString(indexEntry.GetCaseNumber()), document.ISN, activePage))
img1.Save(tempPageFile)
zip.AddFile(tempPageFile, "")
Next
End If
sourceImage.Dispose()
fImage.Dispose()
End If
Mostly it works but when image with different size(in pixels) came that time sourceImage.SelectActiveFrame(FrameDimension.Page, ImagePageCount) fails.
I have observed that it happens only when first page's size is smaller than rest of the pages.
Any thoughts on this.
Thanks
The page size should not affect it. Testing similar code with a 3-page TIFF file where the first page was smaller than the other 2 worked in a .NET 2.0 program.
However, since TIFF can have a different compression format for each page, most likely the failure happens if you hit a page that's not supported by GDI+ on your operating system.
The test file that worked has all 3 pages saved with LZW compression.
See the following post for a discussion of how different Windows versions support different sub-types of TIFF:
C# Generic GDI+ Error when using Image.Save()

Resources