前提・実現したいこと
eclipseで開発をしていたのですが、プロジェクトのプロパティ>javaのビルド・パスのライブラリー、順序およびエクスポートを弄っていたらこのようなエラーが出るようになりプログラムが動かなくなってしまいました。
別のワークスペースにあるプロジェクトのビルドパスを触っていないプログラムも同じエラーが出るようになりました。
エラーが出る前のプログラムソースと全く同じものを実行しています
なにが原因なのか教えてほしいです
osはwindows10です
発生している問題・エラーメッセージ
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\core\src\array.cpp, line 2494 Exception in thread "AWT-EventQueue-0" CvException [org.opencv.core.CvException: cv::Exception: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\core\src\array.cpp:2494: error: (-206) Unrecognized or unsupported array type in function cvGetMat ] at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method) at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:159) at Test.TestHSV.processing(TestHSV.java:471) at Test.act.open(act.java:107) at Test.act.access$1(act.java:103) at Test.act$2.actionPerformed(act.java:78) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6525) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6290) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4881) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2750) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:702) at java.awt.EventQueue$3.run(EventQueue.java:696) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:724) at java.awt.EventQueue$4.run(EventQueue.java:722) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:721) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
該当のソースコード
Java
1package Test; 2 3import java.awt.BorderLayout; 4import java.awt.Color; 5import java.awt.Dimension; 6import java.awt.Image; 7import java.awt.event.ActionEvent; 8import java.awt.event.ActionListener; 9import java.awt.image.BufferedImage; 10import java.awt.image.DataBufferByte; 11import java.awt.image.WritableRaster; 12import java.io.File; 13import java.io.FileInputStream; 14import java.io.IOException; 15 16import javax.imageio.ImageIO; 17import javax.swing.AbstractButton; 18import javax.swing.ImageIcon; 19import javax.swing.JButton; 20import javax.swing.JFileChooser; 21import javax.swing.JFrame; 22import javax.swing.JLabel; 23import javax.swing.JPanel; 24import javax.swing.border.LineBorder; 25import javax.swing.filechooser.FileNameExtensionFilter; 26 27import org.opencv.core.Mat; 28 29public class act { 30 31 File f; 32 JLabel label; 33 JFileChooser File = new JFileChooser(); 34 // Mosaic file = new Mosaic(); 35 TestHSV file = new TestHSV(); 36 static String path; 37 // test 38 private String pa; 39 40 double iconheight2 = 0.0; 41 double iconwidth2 = 0.0; 42 double iconheight3 = 0.0; 43 double iconwidth3 = 0.0; 44 45 public void show() { 46 JFrame frame = new JFrame("不適切画像自動フィルタリグ"); 47 frame.setBounds(100, 100, 500, 400); 48 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 49 50 label = new JLabel(); 51 label.setPreferredSize(new Dimension(100, 80)); 52 label.setHorizontalAlignment(JLabel.CENTER); 53 label.setBorder(new LineBorder(Color.BLACK, 2, true)); 54 55 frame.getContentPane().add(label, BorderLayout.CENTER); 56 57 JPanel p = new JPanel(); 58 JButton btn1 = new JButton("画像選択"); 59 JButton btn2 = new JButton("表示"); 60 JButton btn3 = new JButton("保存"); 61 62 p.add(btn1); 63 p.add(btn2); 64 p.add(btn3); 65 66 frame.getContentPane().add(p, BorderLayout.SOUTH); 67 68 btn1.addActionListener(new ActionListener() { 69 @Override 70 public void actionPerformed(ActionEvent e) { 71 choose(); 72 } 73 }); 74 75 btn2.addActionListener(new ActionListener() { 76 @Override 77 public void actionPerformed(ActionEvent e) { 78 open(); 79 } 80 }); 81 82 frame.setVisible(true); 83 } 84 85 private void choose() { 86 // 画像ファイルの拡張子を設定 87 File.setFileFilter(new FileNameExtensionFilter("画像ファイル", "png", "jpg", 88 "Jpeg", "GIF", "bmp")); 89 // ファイル選択ダイアログを表示、戻り値がAPPROVE_OPTIONの場合、画像ファイルを開く 90 if (File.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { 91 f = File.getSelectedFile(); 92 } 93 } 94 95 public void setpa(String path) { 96 this.pa = path; 97 } 98 99 public String getpa() { 100 return this.pa; 101 } 102 103 private void open() { 104 // path = f.getPath(); 105 setpa(f.getPath()); 106 107 Mat src = file.processing(f.getPath()); 108 109 // 呼び出し 110 ImageIcon icon = new ImageIcon(Mat2Image(src)); 111 112 113 // 高さ、幅がlabalより大きい場合 114 if (((double) label.getWidth() <= (double) icon.getIconWidth()) 115 && ((double) label.getHeight() <= (double) icon.getIconHeight())) { 116 // 幅が高さより大きい場合、幅に合わせる 117 if ((double) icon.getIconWidth() <= (double) icon.getIconHeight()) { 118 iconwidth2 = (double) label.getHeight() 119 * (double) icon.getIconWidth() 120 / (double) icon.getIconHeight(); 121 iconwidth3 = iconwidth2 / (double) icon.getIconWidth(); 122 iconheight2 = (double) icon.getIconHeight() * iconwidth3; 123 124 System.out.println(iconwidth2 + "," + iconheight2); 125 // 高さが幅より大きい場合、高さに合わせる 126 } else if ((double) icon.getIconHeight() <= (double) icon 127 .getIconWidth()) { 128 iconheight2 = (double) label.getWidth() 129 * (double) icon.getIconHeight() 130 / (double) icon.getIconWidth(); 131 iconheight3 = iconheight2 / (double) icon.getIconHeight(); 132 iconwidth2 = (double) icon.getIconWidth() * iconheight3; 133 System.out.println(iconwidth2 + "," + iconheight2); 134 } 135 // 幅がlabelより大きい場合 136 } else if ((double) label.getWidth() <= (double) icon.getIconWidth()) { 137 iconheight2 = (double) label.getWidth() 138 * (double) icon.getIconHeight() 139 / (double) icon.getIconWidth(); 140 iconwidth2 = (double) label.getWidth(); 141 // 高さがlabelより大きい場合 142 } else if ((double) label.getHeight() <= (double) icon.getIconHeight()) { 143 iconheight2 = (double) label.getHeight(); 144 iconwidth2 = (double) label.getHeight() 145 * (double) icon.getIconWidth() 146 / (double) icon.getIconHeight(); 147 } else { 148 iconheight2 = icon.getIconHeight(); 149 iconwidth2 = icon.getIconWidth(); 150 } 151 152 // System.out.println(iconheight2+","+iconwidth2); 153 154 Image image_ = icon.getImage().getScaledInstance((int) iconwidth2, 155 (int) iconheight2, Image.SCALE_SMOOTH); 156 // label.setIcon(icon); 157 ImageIcon icon2 = new ImageIcon(image_); 158 label.setIcon(icon2); 159 } 160 161 public static BufferedImage Mat2Image(Mat src) { 162 163 // Mat srcのチャネル数を取得 164 int type = 0; 165 if (src.channels() == 1) { 166 type = BufferedImage.TYPE_BYTE_GRAY; 167 } else if (src.channels() == 3) { 168 type = BufferedImage.TYPE_3BYTE_BGR; 169 } else { 170 return null; 171 } 172 // 新規BufferedImage型をsrcの幅,縦,チャネル数で作成. 173 BufferedImage image = new BufferedImage(src.width(), src.height(), type); 174 // 作成したBufferedImageからRasterを抜き出す. 175 WritableRaster raster = image.getRaster(); 176 // 抜き出したRasterからバッファを抜き出す. 177 DataBufferByte Buf = (DataBufferByte) raster.getDataBuffer(); 178 byte[] data = Buf.getData(); 179 src.get(0, 0, data); 180 181 return image; 182 } 183} 184
試したこと
新しいワークスペースを作りライブラリのパスも設定しなおし、windowsの環境変数も最初から設定したのですが変わらず
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。