试图读取或写入受保护的内存......错误!(VCS#2010) [英] Attempted to read or write protected memory...Error!(VCS#2010)

查看:127
本文介绍了试图读取或写入受保护的内存......错误!(VCS#2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Coders!

我正在尝试在VSC#2010中制作haar cascade的正面图像构建器(它的开发人员尚未在googlecode上更新)。经过几次解决后,我能够成功构建解决方案。但是当我点击F5时,它会抛出一个异常:

Hi Coders!
I'm trying to make "positive image builder for haar cascade" in VSC#2010(it has not been updated by its developer at googlecode). After going through few work-around I was able to successfully build solution. But when I hit F5, it throws an exception:

An unhandled exception of type 'System.AccessViolationException' occurred in OpenCvSharp.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 



和绿色箭头指向行(在Form1.cs中):


and "green arrow" points to line(in Form1.cs):

private CvCapture FrameCapture = Cv.CreateFileCapture(ConfigurationManager.AppSettings["VideoFile"].ToString());





项目内容:

Form1.cs



Contents of project:
Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Xml;
using System.Configuration;
using System.Diagnostics;
using System.IO;

using OpenCvSharp;
using OpenCvSharp.UserInterface;

namespace MyPositiveImageBuilder
{
    public partial class Form1 : Form
    {
        private CvCapture FrameCapture = Cv.CreateFileCapture(ConfigurationManager.AppSettings["VideoFile"].ToString());
        private IplImage Frame, FrameBak, FrameSave;
        private bool FirstClick = true;
        private int x1, x2, y1, y2, width, height, ImgCount = Convert.ToInt32(ConfigurationManager.AppSettings["ImgIndexBegin"]);
        public Form1()
        {
            InitializeComponent();
            this.KeyPreview = true;
            this.KeyPress += new KeyPressEventHandler(Form_KeyPress);
            this.ImgFrame.MouseClick += new MouseEventHandler(Frame_DrawCrop);
            this.ImgFrame.MouseMove += new MouseEventHandler(Frame_MouseMove);

        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Frame = FrameCapture.QueryFrame();
            FrameBak = Cv.CreateImage(Cv.GetSize(Frame), Frame.Depth, Frame.NChannels);
            FrameSave = Cv.CreateImage(Cv.GetSize(Frame), Frame.Depth, Frame.NChannels);
            Cv.Copy(Frame, FrameBak, null);
            Cv.Copy(Frame, FrameSave, null);

            this.ImgFrame.Image = Frame.ToBitmap();
        }

        private void WritePositive(string WriteData)
        {
            StreamWriter sw = File.AppendText(ConfigurationManager.AppSettings["PositivesFile"].ToString());
            sw.WriteLine(WriteData);
            sw.Close();
        }

        void Form_KeyPress(object sender, KeyPressEventArgs e)
        {
            string KeyPressed = e.KeyChar.ToString().ToLower();

            //'S' key pressed
            //Save region
            if ((e.KeyChar == 115) && (width > 0))
            {
                string SaveImageAs = ConfigurationManager.AppSettings["ImgDirectory"].ToString() + ConfigurationManager.AppSettings["ImgNamePrefix"].ToString() + "_" + ImgCount + ".jpg";

                FrameSave.SaveImage(SaveImageAs);

                WritePositive(SaveImageAs + " 1 " + x1 + " " + y1 + " " + width + " " + height);

                ImgCount++;

                this.CropCount.Text = "Images saved: " + ImgCount.ToString();

                Frame = FrameCapture.QueryFrame();
                this.ImgFrame.Image = Frame.ToBitmap();
            }

            //'Q' key pressed
            //Next frame
            if (e.KeyChar == 113)
            {
                Frame = FrameCapture.QueryFrame();
                FrameBak = Cv.CreateImage(Cv.GetSize(Frame), Frame.Depth, Frame.NChannels);
                Cv.Copy(Frame, FrameBak, null);
                Cv.Copy(Frame, FrameSave, null);

                this.ImgFrame.Image = Frame.ToBitmap();
            }

            //'N' key pressed
            //Negative
            if (e.KeyChar == 110)
            {
                ImgCount++;

                this.ImgFrame.Image.Save(ConfigurationManager.AppSettings["ImgNegatives"].ToString() + "Negative_" + ImgCount + ".jpg");
            }

            //'Escape' key pressed
            if (e.KeyChar == 27)
            {
                this.Close();
            }
        }

        void Frame_DrawCrop(object sender, MouseEventArgs e)
        {
            if (FirstClick)
            {
                x1 = e.X;
                y1 = e.Y;

                Cv.Copy(Frame, FrameBak, null);

                FirstClick = false;
            }
            else
            {
                x2 = e.X;
                y2 = e.Y;
                width = x2 - x1;
                height = y2 - y1;

                if ((x2 > x1) && (y2 > y1))
                {
                    Cv.Copy(Frame, FrameBak, null);

                    this.ImgFrame.Image = Frame.ToBitmap();

                    FirstClick = true;
                }
                else
                {
                    FirstClick = true;

                    MessageBox.Show("Please start in the upper left corner. Proceed to the lower left corner.");

                    this.ImgFrame.Image = FrameBak.ToBitmap();
                }
            }
        }

        void Frame_MouseMove(object sender, MouseEventArgs e)
        {
            Cv.Copy(FrameBak, Frame,null);
            Cv.DrawLine(Frame, new CvPoint(0, e.Y), new CvPoint(Frame.Width, e.Y), new CvColor(0, 255, 0));
            Cv.DrawLine(Frame, new CvPoint(e.X, 0), new CvPoint(e.X, Frame.Height), new CvColor(0, 255, 0));

            this.ImgFrame.Image = Frame.ToBitmap();
        }
    }
}







Program.cs:




Program.cs:

<pre lang="cs">using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace MyPositiveImageBuilder
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}







App.config:




App.config:

<<pre lang="xml">?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="VideoFile" value="E:\HaarTraining\pupil.avi"/>
    <add key="PositivesFile" value="E:\HaarTraining\Positives.txt" />
    <add key="ImgDirectory" value="E:\HaarTraining\Images\Positives\" />
    <add key="ImgNamePrefix" value="Pupil"/>
    <add key="ImgIndexBegin" value="00"/>
    <add key="ImgNegatives" value="E:\"/>
  </appSettings>
</configuration



>



Form1.Designer.cs:


>

Form1.Designer.cs:

namespace MyPositiveImageBuilder
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.ImgFrame = new System.Windows.Forms.PictureBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.CropCount = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.ImgFrame)).BeginInit();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // ImgFrame
            // 
            this.ImgFrame.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.ImgFrame.Cursor = System.Windows.Forms.Cursors.Cross;
            this.ImgFrame.Location = new System.Drawing.Point(12, 12);
            this.ImgFrame.Name = "ImgFrame";
            this.ImgFrame.Size = new System.Drawing.Size(320, 240);
            this.ImgFrame.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
            this.ImgFrame.TabIndex = 2;
            this.ImgFrame.TabStop = false;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new System.Drawing.Point(732, 12);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(190, 153);
            this.groupBox1.TabIndex = 3;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Directions";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(15, 127);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(64, 13);
            this.label4.TabIndex = 3;
            this.label4.Text = "Negative: N";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(15, 92);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(70, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Save Crop: S";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(15, 60);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(75, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "Next Frame: Q";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(15, 28);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(53, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Quit: ESC";
            // 
            // CropCount
            // 
            this.CropCount.AutoSize = true;
            this.CropCount.Location = new System.Drawing.Point(747, 181);
            this.CropCount.Name = "CropCount";
            this.CropCount.Size = new System.Drawing.Size(0, 13);
            this.CropCount.TabIndex = 4;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(934, 512);
            this.Controls.Add(this.CropCount);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.ImgFrame);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.ImgFrame)).EndInit();
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.PictureBox ImgFrame;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label CropCount;
    }
}





我不擅长编程以解决此内存访问问题。请帮忙。

pupil.avi出现在E:\HaarTraining\pupil.avi,所有其他文件也出现在App.config中的指定位置。



提前感谢您的帮助!



I'm not that good at programming to resolve this memory access.Please help.
pupil.avi is present at "E:\HaarTraining\pupil.avi" and all other file are also present at specified locations as in "App.config".

Thanks in advance for yoour help!

推荐答案

要完成OpenCV的安装,您可以必须重新启动Windows。



如果通过重新启动无法解决,请将以下文件从< OpenCV install

目录> / bin复制到您的VisualStudio项目目录(bin / Debug)。

cv110.dll

cxcore110.dll

cxts001.dll

ffopencv110.dll

highgui110.dll

ml110.dll
To complete the installation of OpenCV, you may have to restart Windows.

If not settled by restarting, copy the following files from <OpenCV install
directory>/bin to your VisualStudio project directory (bin/Debug).
cv110.dll
cxcore110.dll
cxts001.dll
ffopencv110.dll
highgui110.dll
ml110.dll


这篇关于试图读取或写入受保护的内存......错误!(VCS#2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆